Placing a primitive variable in an object is known as
boxing
. Boxing allows the primitive to be used where objects are required. For this purpose, Java provides wrapper classes to implement boxing for each primitive type—namely,
Byte,
Short,
Integer,
Long,
Float,
Double,
Character, and
Boolean. An
Integer object, for example, can hold a variable of the type
int.
int iPrimitive = 5;
Integer iWrapper = new Integer(iPrimitive); // boxing
The opposite of boxing is, naturally,
unboxing
, which converts the object type back into its primitive type.
iPrimitive = iWrapper.intValue(); ...