Programming |
Data types are used to provide important information to the compiler about the data being used in a program. That information helps the compiler in assigning memory space required for the data and the range of the data which can be used. In java we can use following types of data types:
Data type |
Size required |
Default value |
Minimum value |
Maximum value |
boolean |
Unspecified/JVM Specific |
false |
true or false |
|
char |
2 (16 bits) |
ASCII-0 |
0 |
215-1 (32767) |
Unicode-\u0000 |
('\u0000') |
('\uFFFF') |
||
byte |
1 (8 bits) |
0 |
-27 (–128) |
27-1(–127) |
short |
2 (16 bits) |
0 |
-215 (–32768) |
215-1 (32767) |
int |
4 (32 bits) |
0 |
-231 (–2147483648) |
231-1 (2147483647) |
long |
8 (64 bits) |
0L |
-263 |
263-1 |
float |
4 (32 bits) |
0.0f |
-3.4E+38 |
+3.4E+38 |
double |
8 (64 bits) |
0.0d |
-1.7E+308 |
+1.7E+308 |
Why Non-primitives don’t have pre-defined size?
Because all the things defined under non-primitives are not constant. They depend on the user. Nobody can know what are the values the user is going to be storing in a String literal or the number of elements in an Array or number of variables, methods inside a class.