There are two distinct, fundamental types in the Java language:
objects and primitives. Java provides type safety by enforcing static
typing, which requires that every variable must be declared with its
type before it is used. For example, a variable named
declared as type
int (a primitive 32-bit integer) looks
This mechanism stands in contrast to nonstatically typed languages where variables are only optionally declared. Though explicit type declarations are more verbose, they enable the compiler to prevent a wide range of programming errors—accidental variable creation resulting from misspelled variable names, calls to nonexistent methods, and so on—from ever making it into running code. Details of the Java Type System can be found in the Java Language Specification.
Java primitive types are not objects and do not support the operations associated with objects described later in this chapter. You can modify a primitive type only with a limited number of predefined operators: “+”, “-”, “&”, “|”, “=”, and so on. The Java primitive types are:
An 8-bit 2’s-complement integer
A 16-bit 2’s-complement integer
A 32-bit 2’s-complement integer
A 64-bit 2’s-complement integer
A 16-bit unsigned integer representing a UTF-16 code unit
A 32-bit IEEE 754 floating-point number
A 64-bit IEEE 754 floating-point number
Java is an object-oriented language and focuses not on ...