Monday, May 05, 2008

Primitive Data Types in Java

Java supports 8 built-in data types.


boolean - This data type is 1 bit in size and is used to represent a binary
condition, true or false.


byte - This data type is an 8-bit signed 2’s complement integer.
It can hold values ranging from -128 to 127.


short - This data type is a 16-bit signed 2’s complement integer.
It can hold values ranging from -32,768 to 32,767.


char - This data type is a 16-bit unsigned integer used to represent unicode characters.
It can hold values ranging from 0 to 65,535.


int - This data type is a 32-bit signed 2’s complement integer.
It can hold values ranging from -2,147,483,648 to 2,147,483,647.


long - This data type is a 64-bit signed 2’s complement integer.
It can hold values raging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.


float - This data type is a 32-bit signed floating-point number.
The range of values it can hold is +/–3.40282347^38.


double - This data type is a 64-bit signed floating-point number.
The range of values it can hold is +/–1.79769313486231570^308.


The syntax for declaring and initializing a primitive is:



<modifier> <type> <variableName> = <initialvalue>

No comments: