name
|
purpose of the type |
default value |
examples of literal values |
boolean |
logical values |
false |
false, true |
char |
Unicode characters |
\u0000
|
' ',
'A',
'\101',
'\u0041',
'\'',
'\t'
|
byte |
signed integers |
0 |
use int literal values
|
short |
signed integers |
0 |
use int literal values
|
int |
signed integers |
0 |
0, 42, 2147483647
|
long |
signed integers |
0 |
0L, 42L, 9223372036854775807L
|
float |
IEEE 754 floating pt. values |
0.0 |
0.0F, 9.81F, 2.9979E8F, 6.6252e-34F
|
double |
IEEE 754 floating pt. values |
0.0 |
0.0, 9.81, 1.0e100, 0.5E-100
|
Later we will see that
the fields of a
class declaration
are initially given the
default value
given above,
whereas a variable declared in a
method declaration
has no default value.
However,
a Java compiler will generate a compilation error
for most attempts to use an uninitialized variable.
In Java, each of these types has a
range that is defined by
the language. So the range does not change as you move your
Java source code from one platform to another.
Here are the ranges:
name |
size (bits) |
smallest value of type |
largest value of type |
boolean |
1 |
N/A |
N/A
|
char |
16 |
\u0000
|
\uFFFF
|
byte |
8 |
-128 |
+127
|
short |
16 |
-32768 |
+32767
|
int |
32 |
-2147483648 |
+2147483647
|
long |
64 |
-9223372036854775808 |
+9223372036854775807
|
float |
32 |
-3.40282347E+38 |
+3.40282347E+38
|
double |
64 |
-1.79769313486231570E+308 |
+1.79769313486231570E+308
|
Values of the types
float
and
double
that are small in magnitude are considered to be zero:
name
|
smallest negative value |
smallest positive value
|
float |
-1.40239846E-45 |
+1.40239846E-45
|
double |
-4.94065645841246544E-324 |
+4.94065645841246544E-324
|