2.2 Primitive Data Types
Figure 2.1 gives an overview of the primitive data types in Java.
Figure 2.1. Primitive Data Types in Java
Primitive data types in Java can be divided into three main categories:
Primitive data values are not objects. Each primitive data type defines the range of values in the data type, and operations on these values are defined by special operators in the language (see Chapter 3).
Each primitive data type also has a corresponding wrapper class that can be used to represent a primitive value as an object. Wrapper classes are discussed in Section 10.3.
Table 2.9. Range of Integer Values
Integer data types are byte , short , int , and long (see Table 2.9). Their values are signed integers represented by 2's complement (see Section G.4, p. 598).
Table 2.10. Range of Character Values
The first 128 characters of the Unicode set are the same as the 128 characters of the 7-bit ASCII character set, and the first 256 characters of the Unicode set
Table 2.11. Range of Floating-point Values
Floating-point numbers are represented by the float and double data types.
Floating-point numbers conform to the IEEE 754-1985 binary floating-point standard. Table 2.11 shows the range of values for positive floating-point numbers, but these apply equally to negative floating-point numbers with the '-' sign as prefix. Zero can be either 0.0 or -0.0 .
Since the size for representation is finite, certain floating-point numbers can only be represented as approximations. For example, the value of the expression
is represented as an
Table 2.12. Boolean Values
The data type boolean represents the two logical values denoted by the literals true and false (see Table 2.12).
Boolean values are produced by all
(see Section 3.9),
(see Section 3.12) and
boolean logical operators
(see Section 3.11), and are primarily used to
Table 2.13 summarizes the pertinent facts about the primitive data types: their width or size, which indicates the number of the bits required to store a primitive value; their range (of legal values), which is specified by the minimum and the maximum values permissible; and the
Table 2.13. Summary of Primitive Data Types