Java Reference
In-Depth Information
NOTE
Technically, the Java run-time system can use any size it wants to store a primitive type.
However, in all cases, types must act as specified.
The most commonly used integer type is
int
. Variables of type
int
are often employed to
control loops, to index arrays, and to perform general-purpose integer math.
When you need an integer that has a range greater than
int
, use
long
. For example, here
is a program that computes the number of cubic inches contained in a cube that is one mile
by one mile, by one mile:
Here is the output from the program:
Clearly, the result could not have been held in an
int
variable.
The smallest integer type is
byte
. Variables of type
byte
are especially useful when
working with raw binary data that may not be directly compatible with Java's other built-in