Java Reference
In-Depth Information
Table 2.1
Java primitive data types.
Type
Values
Default
Size
Range
-128 to 127
byte
signed integer
0
8-bit
-32768 to 32767
short
signed integer
0
16-bit
-2147483648 to 2147483647
int
signed integer
0
32-bit
-9223372036854775808 to
9223372036854775807
long
signed integer
0
64-bit
- 1.4012985E-45 to
- 3.4028235E+38,
- infinity, - 0, NaN
float
IEEE 754
floating-point
0.0
32-bit
- 4.9E-324 to
- 1.7976931348623157E+308,
- infinity, - 0, NaN
double
IEEE 754
floating-point
0.0
64-bit
\ u0000 or 0
\ u0000 to
\ uFFFF or
char
Unicode character
or Unsigned integer
16-bit
0 to 65535
boolean
true, false
false
1 bit in 32
bit integer
Not applicable
The IEEE 754 floating-point standard is used for the 32-bit float and 64-bit
double types. We discuss floating-point in more detail later in Section 2.11 and
in Appendix 3.
Historically, standard characters were typically represented with the 7-bit
ASCII encoding. Various other 8-bit encoding schemes exist to provide an addi-
tional 128 characters for symbols or for the characters needed for particular
languages. To provide internationalization with a single encoding requires more
than the 256 characters available with 1 byte. The Java designers decided to
use the 2-byte character type encoding called the Unicode system for the char
type. (J2SE 5.0 adds support for an even larger 4-byte system known as Uni-
code 4.0.) The char type can also act as a 16-bit unsigned integer in some
cases. (See Section 9.7 for more about character encoding.)
The boolean (true/false) type provides for the many kinds of logical
operations carried out in almost any program. Though internally a boolean value
is eithera1or0integer, it cannot be used in arithmetic operations. (Represen-
tations of Boolean arrays are not specified for the JVM. Some implementations
use bit arrays.)
We discuss classes and objects later, but we note here that primitive types in
Java are not instances of classes. The decision to use simple data types broke
the symmetry and elegance of the language to some degree but vastly reduced
overhead and execution times compared to the case where all data types are
objects.
Search WWH ::




Custom Search