You saw in Chapter 3, that although Java is a language based on classes, it does support a set of primitive data types that includes int, boolean, and float among others. These types are used extensively, but there are situations in which treating primitives as true Java objects would be more useful. In fact, the java.lang package includes a set of wrapper classes for the primitive data types to serve this purpose. This set consists of Boolean, Byte, Character, Double, Float, Integer, Long, and Short. Each of these classes provides an immutable object representation of its corresponding primitive type. The methods defined by the classes consist mainly of conversion and comparison operations. Each class also overrides toString() and equals() to provide an intuitive text representation and a simple equality check for wrapped values. |