Misplaced Pages

Primitive wrapper class in Java

Article snapshot taken from[REDACTED] with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

This is an old revision of this page, as edited by Chip Zero (talk | contribs) at 14:18, 11 November 2006 (added Atomic wrapper classes). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 14:18, 11 November 2006 by Chip Zero (talk | contribs) (added Atomic wrapper classes)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A primitive wrapper class in the Java programming language is one of eight classes provided in the java.lang package to provide object methods for the eight primitive types. All of the primitive wrapper classes in Java are immutable. J2SE 5.0 introduced autoboxing of primitive types into their wrapper object, and automatic unboxing of the wrapper objects into their primitive value—the implicit conversion between the wrapper objects and primitive values.

Wrapper classes are used to represent primitive values when an Object is required. The wrapper classes are used extensively with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection package.

The primitive wrapper classes and their corresponding primitive types are:

Primitive type Wrapper class
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean

The Byte, Short, Integer, Long, Float, and Double wrapper classes are all subclasses of the Number class.

Void

Although it is not a wrapper class, the Void class is similar in that it provides an object representation of the void return type. The Void class is an uninstantiable placeholder class used by the java.lang.reflect API to hold a reference to the Class object representing the Java keyword void.

Atomic wrapper classes

With Java 5.0, additional wrapper classes were introduced in the java.util.concurrent.atomic package, such as the AtomicInteger class. These classes cannot be used as a replacement for the regular wrapper classes, and are not immutable. Instead, they provide atomic operations such as addition and increment.

See also

Category:
Primitive wrapper class in Java Add topic