Primitive variable wrapper classes are aptly named because they are used to wrap a class around a primitive data type value. They are contained in the java.lang package so they are accessible to any program. The importance of primitive variable wrapper classes is evident when you want to pass a primitive value to a method or constructor that takes an Object argument. You cannot, for example, store primitive values in a TreeSet collection, but if you place a wrapper class around the primitive value the wrapper class object can be stored in a TreeSet . The primitive variable wrapper classes define methods that can be used to convert String objects into wrapper class objects or into primitive values. This can be very useful when reading character data from input files or when a Web-based application such as a Java servlet receives String input arguments from a client request. The input String is parsed into substring elements, and a primitive variable wrapper class method converts the appropriate substring into a primitive value. More details on this process are provided later in this chapter. Table 15.1. Primitive Variable Wrapper Classes
There is a primitive variable wrapper class for every primitive data type. Table 15.1 lists the declarations for the wrapper classes. When a class implements the Serializable interface it indicates that an instance of the class can be persistently stored. Usually this means an object can be written to or restored from disk. The Number class is the abstract parent class for the numerical primitive variable wrapper classes. |