JAVA Data Type

Data types in Java

data_types_in_java

Primitive data types : JAVA

There are majorly two types of languages. First one is Statically typed language where each variable and expression type is already known at compile time.Once a variable is declared to be of a certain data type, it cannot hold values of other data types.Example: C,C++, Java. Other, Dynamically typed languages: These languages can receive different data types over the time. Ruby, Python

Java has two categories of data:

  • Primitive data (e.g., number, character)
  • Object data (programmer created types)

Primitive data are only single values; they have no special capabilities.
The eight primitive data types in Java are:

  • boolean, the type whose values are either true or false
  • char, the character type whose values are 16-bit Unicode characters
  • the arithmetic types:
    • the integral types:
      • byte
      • short
      • int
      • long
    • the floating-point types:
      • float
      • double

Values of class type are references. Strings are references to an instance of class String.

Primitive data types in Java
TypeDefaultSizeExample Literals
booleanfalse1 bittrue, false
byte08 bits(none)
char\u000016 bits 'a', '\u0041', '\101', '\\', '\'', '\n', 'ß'
short016 bits(none)
int032 bits-2, -1, 0, 1, 2
long064 bits-2L, -1L, 0L, 1L, 2L
float0.032 bits 1.23e100f, -1.23e-100f, .3f, 3.14F
double0.064 bits 1.23456e300d, -1.23456e-300d, 1e1d

Boolean

Values of type boolean are not converted implicitly or explicitly (with casts) to any other type. But the programmer can easily write conversion code:

final int i = b?1:0;
final double d = b?1.0:0.0;
final boolean b = i>0?true:false;

Character

The 16-bit Unicode character set underlies both the Java source program and char data type. So, not only are Java programs written in Unicode characters, but Java programs can manipulate Unicode data.

Numeric

Range of numeric data types in Java
TypeSizeRange
byte8 bits-128 .. 127
short16 bits-32,768 .. 32,767
int32 bits-2,147,483,648 .. 2,147,483,647
long64 bits-9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807
float32 bits 3.40282347 x 1038, 1.40239846 x 10-45
double64 bits 1.7976931348623157 x 10308, 4.9406564584124654 x 10-324


If you like dEexams.com and would like to contribute, you can also write your article here or mail your article to admin@deexams.com . See your article appearing on the dEexams.com main page and help others to learn.


Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.


Python if , elif and else

Python Conditions and If statements

  • 0
Python for beginners

Learning Python Part 1

  • 3
Struct Alignment and Padding

Struct Alignment and Padding in C++ And C

  • 0
Friend function

Friend function C++

  • 0
Pointers

C++ Pointers

  • 0
Structures

C++ Structures

  • 0
Types of Inheritance in C++

Inheritance and access specifiers C++

  • 0
Java date pattern

Java Date Pattern Syntax

  • 0
Java Date and Calendar

Java Date formats

  • 0
JAVA Data Type

Data types in Java

  • 0
Java unreachable code

Unreachable Code Error in Java

  • 0

Post Comment

Comments(0)

WEB TECHNOLOGY

Articles

×

Forgot Password

Please enter your email address below and we will send you information to change your password.