Primitive wrapper class in Java

In object-oriented programming, a wrapper class is a class that encapsulates types, so that those types can be used to create object instances and methods in another class that needs those types. So a primitive wrapper class is a wrapper class that encapsulates, hides or wraps data types from the eight primitive data types, so that these can be used to create instantiated objects with methods in another class or in other classes. The primitive wrapper classes are found in the Java API.

Primitive wrapper classes are used to create an that needs to represent primitive types in   classes (i.e., in the Java API), in the  package and in the  reflection package. Collection classes are Java API-defined classes that can store objects in a manner similar to how data structures like arrays store primitive data types like int, double, long or char, etc., but arrays store primitive data types while collections actually store objects.

The primitive wrapper classes and their corresponding primitive types are:


 * {| class="wikitable"

! Primitive type !! Wrapper class !! Constructor arguments
 * || ||   or
 * || ||   or
 * || ||   or
 * || ||   or
 * || || ,   or
 * || ||   or
 * || ||   or
 * }
 * || || ,   or
 * || ||   or
 * || ||   or
 * }
 * || ||   or
 * }
 * || ||   or
 * }
 * }

The difference between wrapper classes and primitive types
Primitive wrapper classes are not the same thing as primitive types. Whereas variables, for example, can be declared in Java as data types double, short, int, etc., the primitive wrapper classes create instantiated objects and methods that inherit but hide the primitive data types, not like variables that are assigned the data type values.

Therefore, the term Primitive wrapper class does not mean that wrapper classes are primitive types. It should be understood to be a class that wraps primitive types. Wrapper classes can be used to store the same value as of a primitive type variable but the instances/objects of wrapper classes themselves are Non-Primitive. We cannot say that Wrapper classes themselves are Primitive types. They just wrap the primitive types.

The,  ,  ,  ,  , and   wrapper classes are all subclasses of the  class.

The wrapper classes  and   are not one of the primitive wrapper classes but are immutable.

Atomic wrapper classes
With Java 5.0, additional wrapper classes were introduced in the package. These classes are mutable and cannot be used as a replacement for the regular wrapper classes. Instead, they provide atomic operations for addition, increment and assignment.

The atomic wrapper classes and their corresponding types are:


 * {| class="wikitable"

! Primitive type !! Wrapper class
 * }
 * }
 * }
 * }
 * }
 * }
 * }
 * }
 * }

The  and   classes are subclasses of the   class. The  class accepts the type parameter   that specifies the type of the object reference. (See "Generics in Java" for a description of type parameters in Java).