Wrapping the Primitive Types in Classes

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 ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.