## Section8.2Types

In Java, we distinguish primitive types and reference types. The reference types are further categorized into classes and array types. The primitive types are very similar to types we know from C. However, their size and arithmetic is exhaustively defined in Java.

The primitive types can be implicitly converted according to the order in Figure 8.2.2. This order results from the subset relation of the value ranges given in Table 8.2.1. char is the only unsigned data type in java and therefore neither subset nor superset of short and byte. The type boolean cannot be converted implicitly to another type and no type is implicitly converted to boolean.

For other conversions (excluding conversions to boolean), we can use explicit type casts: The expression (T)e converts the subexpression e to the type T. Such explicit casts can lose precision. For instance, (byte)1024 is equal to 0.

### Example8.2.3.Implicit and Explicit Type Conversions.

short s = 1;
byte  b = 2;
int   i = 3;
i = s; // ok
b = s; // not ok, as short is not implicitly
// convertible to byte
b = (byte)s; // ok, as it is an explicit cast