Types

A type is a set of values and appropriate operations. Java's built-in primitive types are byte, short, int, long, float, double, char, and boolean. A reference type is associated with each class and interface.

Primitive types

Numeric types

Numeric types are sets of numeric values. Numeric types are char, byte, short, int, long, float, or double. The first five are integral types, the last two are floating point types. (It may surprise you to see char listed as an integral type, but alas it is true.)

The values of the integral types are integers in the following ranges:

The types byte, short, int, and long represent integers using 8, 16, 32, and 64-bit 2's complement representations respectively.

The type char represents characters using the Unicode 16-bit encoding. See http://www.unicode.org for details about the Unicode character set. The first 128 Unicode characters are the familiar ASCII (American Standard Code for Information Interchange) characters. See, for instance, http://www.bbsinc.com/iso8859.html for the ASCII code.

Values of types float and double are stored as 32 and 64-bit floating point values respectively. Values of type float have about seven places of accuracy, and values of type double about 16.

The smallest positive non-zero float is 1.4 x 10-45; the largest is 3.4028235 x 1038. The smallest positive non-zero double is 5.0 x 10-324; the largest is 1.7976931348623157 x 10308.

Boolean type

The type boolean contains only two values, denoted by the literals true and false.

Reference types

Each class and interface has an associated reference type. The values of a reference type denote instances of the class or interface, and are thus called reference values. Each object has a unique reference value associated with it. Equal reference values denote the same object.

There is a unique reference value denoted by the literal null that does not reference any object. This value can be considered to be an element of every reference type.

If one class is a subclass of another, then the reference type associated with the first class is a subset of the reference type associated with the second. For instance, if class B extends class A, then every B instance is also an A. Thus a reference-to-B is also a reference-to-A, and the set of reference-to-B's is a subset of the set of reference-to-A's. The type reference-to-B is said to be a subtype of the type reference-to-A.

The situation is similar with interfaces. If class A implements interface I, then every A instance is also an I, and the type reference-to-A is a subtype of the type reference-to-I.

In summary, the reference type for a class is composed of references to instances of the class and references to instances of subclasses of the class. The reference type for an interface is composed of references to instances of classes that implement the interface.


Fred Hosch
Last modified: Wed Aug 29 13:22:52 CDT 2001