Java Reference
In-Depth Information
The primitive types are defined to be the same on all machines and in all implementations,
and are various sizes of two's-complement integers, single- and double-precision IEEE 754
standard floating-point numbers, a boolean type, and a Unicode character char type. Values
of the primitive types do not share state.
Reference types are the class types, the interface types, and the array types. The reference
types are implemented by dynamically created objects that are either instances of classes or
arrays. Many references to each object can exist. All objects (including arrays) support the
methods of the class Object , which is the (single) root of the class hierarchy. A predefined
String class supports Unicode character strings. Classes exist for wrapping primitive values
inside of objects. In many cases, wrapping and unwrapping is performed automatically by
the compiler (in which case, wrapping is called boxing, and unwrapping is called unbox-
ing). Class and interface declarations may be generic, that is, they may be parameterized by
other reference types. Such declarations may then be invoked with specific type arguments.
Variables are typed storage locations. A variable of a primitive type holds a value of that
exact primitive type. A variable of a class type can hold a null reference or a reference to
an object whose type is that class type or any subclass of that class type. A variable of an
interface type can hold a null reference or a reference to an instance of any class that im-
plements the interface. A variable of an array type can hold a null reference or a reference
to an array. A variable of class type Object can hold a null reference or a reference to any
object, whether class instance or array.
Chapter 5 describes conversions and numeric promotions. Conversions change the
compile-time type and, sometimes, the value of an expression. These conversions include
the boxing and unboxing conversions between primitive types and reference types. Numer-
ic promotions are used to convert the operands of a numeric operator to a common type
where an operation can be performed. There are no loopholes in the language; casts on ref-
erence types are checked at run time to ensure type safety.
Chapter 6 describes declarations and names, and how to determine what names mean (de-
note). The language does not require types or their members to be declared before they are
used. Declaration order is significant only for local variables, local classes, and the order
of initializers of fields in a class or interface.
The Java programming language provides control over the scope of names and supports
limitations on external access to members of packages, classes, and interfaces. This helps
in writing large programs by distinguishing the implementation of a type from its users and
those who extend it. Recommended naming conventions that make for more readable pro-
grams are described here.
Search WWH ::




Custom Search