THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
double 64-bit IEEE 754 floating-point number

Each primitive data type has a corresponding class type in the java.lang package. These wrapper
classesBoolean, Character, Byte, Short, Integer, Long, Float, and Doublealso define useful
constants and methods. For example, most wrapper classes declare constants MIN_VALUE and MAX_VALUE
that hold the minimum and maximum values for the associated primitive type.


The Float and Double classes also have NaN, NEGATIVE_INFINITY, and POSITIVE_INFINITY
constants. Both also provide an isNaN method that tests whether a floating-point value is "Not a
Number"that is, whether it is the result of a floating-point expression that has no valid result, such as dividing
zero by zero. The NaN value can be used to indicate an invalid floating-point value; this is similar to the use
of null for object references that do not refer to anything. The wrapper classes are covered in detail in
Chapter 8.


There is no unsigned integer type. If you need to work with unsigned values originating outside your program,
they must be stored in a larger signed type. For example, unsigned bytes produced by an analog-to-digital
converter, can be read into variables of type short.


The reference types are class types, interface types, and array types. Variables of these types can refer to
objects of the corresponding type.


Each type has literals, which are the way that constant values of that type are written. The next few
subsections describe how literal (unnamed) constants for each type are specified.


7.2.1. Reference Literals


The only literal object reference is null. It can be used anywhere a reference is expected. Conventionally,
null represents an invalid or uncreated object. It has no class, not even Object, but null can be assigned
to any reference variable.


7.2.2. Boolean Literals


The boolean literals are true and false.


7.2.3. Character Literals


Character literals appear with single quotes: 'Q'. Any valid Unicode character can appear between the
quotes. You can use \uxxxx for Unicode characters inside character literals just as you can elsewhere.
Certain special characters can be represented by an escape sequence:


\n newline (\u000A)

\t tab (\u0009)

\b backspace (\u0008)

\r return (\u000D)

\f form feed (\u000C)

\\ backslash itself (\u005C)
Free download pdf