14.07.2013 Views

Contents - Cultural View

Contents - Cultural View

Contents - Cultural View

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Primitive wrapper class 255<br />

Primitive wrapper class<br />

A primitive wrapper class in the Java programming language is one of eight classes provided in the java.lang<br />

package to provide object methods for the eight primitive types. All of the primitive wrapper classes in Java are<br />

immutable. J2SE 5.0 introduced autoboxing of primitive types into their wrapper object, and automatic unboxing of<br />

the wrapper objects into their primitive value—the implicit conversion between the wrapper objects and primitive<br />

values.<br />

Wrapper classes are used to represent primitive values when an Object is required. The wrapper classes are used<br />

extensively with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection<br />

package.<br />

The primitive wrapper classes and their corresponding primitive types are:<br />

Primitive type Wrapper class Constructor<br />

Arguments<br />

byte Byte byte or String<br />

short Short short or String<br />

int Integer int or String<br />

long Long long or String<br />

float Float float, double or String<br />

double Double double or String<br />

char Character char<br />

boolean Boolean boolean or String<br />

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

Void<br />

Although it is not a wrapper class, the Void class is similar in that it provides an object representation of the void<br />

return type. The Void class is an uninstantiable placeholder class used by the java.lang.reflect API to hold a<br />

reference to the Class object representing the Java keyword void..<br />

Atomic wrapper classes<br />

With Java 5.0, additional wrapper classes were introduced in the java.util.concurrent.atomic package. These classes<br />

are mutable and cannot be used as a replacement for the regular wrapper classes. Instead, they provide atomic<br />

operations for addition, increment and assignment.<br />

The atomic wrapper classes and their corresponding types are:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!