4.1. Wrapper Classes

As we saw in the last chapter, all of the eight primitive types (int, short, boolean, double, etc.) are not objects. In order to work with primitive data type variables as if they were objects, Java provides a wrapper class that defines certain constants and methods. Generally, a wrapper class provides behavioral features that enhance the usability of another entity that it “wraps,” or contains, without modifying the thing it wraps. In the case of Java primitive data type wrappers, the wrapper embeds the primitive data type as a field and provides methods for retrieving the value in different forms and doing comparisons, as well as constants appropriate to each class of primitive type. For example, in the last chapter we ...

Get Java™ for ColdFusion® Developers 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.