There are some types which we use very frequently in Java programs known as primitive type and these types get special treatment. As to create any variable we need to make instance of a type using new keyword which creates an object in heap which is not efficient in cases of very frequent uses.
In cases of primitive type we don’t need to use new keyword to make variable, it automatically creates a variable which has not reference and stored on stack and holds value of that variable that is why it is more efficient.
Java determines the size of each primitive type. These sizes don’t change from one machine architecture to another. This means size of primitive type is same on all type of machine.
Here is list of java primitive types
Type |
Contains |
Default |
Size |
Range |
Wrapper |
boolean |
true or false |
false |
Not defined, represent 1 bit information |
NA |
Boolean |
char |
Unicode character |
u0000 |
16 bits or |
0 to 216-1 or |
Character |
byte |
Signed integer |
0 |
8 bit or |
-27 to 27-1 or |
Byte |
short |
Signed integer |
0 |
16 bit or |
-215 to 215-1 or |
Short |
int |
Signed integer |
0 |
32 bit or |
-231 to 231-1 or |
Integer |
long |
Signed integer |
0 |
64 bit or |
-263 to 263-1 or |
Long |
float |
IEEE 754 floating point |
0.0f |
32 bit or |
?1.4E-45 to |
Float |
double |
IEEE 754 floating point |
0.0 |
64 bit or |
?439E-324 to |
Double |
All numeric types are signed. The size of the boolean type is not explicitly specified; it is only defined to be able to take the literal values true or false.
There are wrapper classes for the primitive data types allow you to make a nonprimitive object on the heap to represent that primitive type. For example:
char c = \'x\'; Character C = new Character(c); Or you could also use: Character C = new Character(\'x\');