Java Language / Variables and Data Types
Java Variables
It is a data named used to store a data value. It should be declared for its data type.
Data Type
It tells us what kind of value we are going to store in a variable based on that the system will allocate the storage space.
Type
|
Default Value
|
Size in Bytes
|
Range
|
byte
|
0
|
1 byte
|
-128 to 127
|
short
|
0
|
2 bytes
|
-32,768 to 32,767
|
int
|
0
|
4 bytes
|
-2,147,483,648 to 2,147,483, 647
|
long
|
0
|
8 bytes
|
-9,223,372,036,854,775,808 to 9.22E+18
|
float
|
0.0f
|
4 bytes
|
approximately ±3.40282347E+38F (6-7 significant decimal digits)
Java implements IEEE 754 standard
|
double
|
0.0d
|
8 bytes
|
approximately ±1.79769313486231570E+308 (15 significant decimal digits)
|
char
|
'\u0000'
|
2 byte
|
0 to 65,536 (unsigned)
|
boolean
|
false
|
not precisely defined
|
true or false
|
|