3.1 Data types

Previous Index Next


 In Java there are two kinds of data types reference data types (classes) and primitive data types. All primitive data types have the same byte size and ordering regardless of what kind of hardware platform the Java VM is running on. The primitive data types all have a matching object that implements the data type in an object form. These object also provide useful functions like converting the primitive data type to and from strings.

The Java primitive data types are listed in the table below
 
Primitive Type Byte Size Number Range Matching Object
boolean 8 bit, values true or false  NA Boolean
byte 8 bit signed two's complement integer -128 to 127 inclusive Byte
short 16 bit signed two's complement integer -32768 to 32767 inclusive Short
 int 32 bit signed two's complement integer -2147483648 to 2147483647 inclusive Integer
long 64 bit signed two's complement integer -9223372036854775808 to 9223372036854775807 inclusive Long
char 16 bit unsigned integers representing Unicode characters '\u0000' to '\uffff' inclusive, that is from 0 to 65535 Character
float  32 bit IEEE 754 floating point number 1.40129846432481707e-45 to 3.40282346638528860e+38 inclusive  Float
double 64 bit IEEE 754 floating point number 4.94065645841246544e-324 to 1.79769313486231570e+308 inclusive  Double

A variable can be declared as follows:

int myInt;     //declares an integer called myInt
float myFloat; //declares a floating point number called myFloat
A variable can be initialized when it is declared as follows:
int zeroInt =0; //declares an integer called zeroInt and initializes it to 0
float oneFloat=1.0; //declares a floating point number called oneFloat



Sources