Java Reference
In-Depth Information
Figure 5-4.
This explanation of reference variables was necessary because there is another category of variables called
primitive variables. A primitive variable actually holds the value assigned to it. One of the reasons a primitive variable
holds the assigned value is because each primitive variable type is fixed in size (unlike complex objects such as a
String or Employee, which can vary in size). Java stores numeric information, single characters, and Boolean values
(true or false) in primitive variables. Within the numeric types, the variables store either whole numbers (integers)
or floating points (numbers with decimals). A list of primitive variable types and their characteristics can be seen
in Table 5-1 .
Table 5-1.
Primitive Type
Value Type
Value Range
Space
Allocated
Notes
boolean
logical
true or false
default is false
char
single character
any of Unicodes's 65,436 characters
16 bits
single quotes to
specify value
byte
whole number
-128 to 127
8 bits
short
whole number
- 32,768 to 32,767
16 bits
int
whole number
-2,147,483,648 to 2,147,483,647
32 bits
long
whole number
- 9*10**18 to 9*10**18-1
64 bits
float
floating point
Up to 7 digits of precision
32 bits
Rounds values > limit
double
floating point
Up to 15 digits of precision
64 bits
Rounds values > limit
 
 
Search WWH ::




Custom Search