Wednesday, December 7, 2011

Boxing/Unboxing - Primitive Type wrappers

Java provides Auto Boxing/Un-boxing functionality as we cannot use primitive types to store in Collection framework (deals with Object References).

For each primitive type in Java, we have an equivalent Object wrapper.

boolean - Boolean (1 bit storage for primitive data type)
byte - Byte (1 byte storage for primitive data type)
short - Short ; char - Character (2 bytes storage for short or char - primitive data types)
int - Integer (4 bytes storage for primitive data type)
long - Long (8 bytes storage for primitive data type)
float - Float (4 bytes storage for primitive data type)
double - Double (8 bytes storage for primitive data type)

Boxing / Unboxing functionality in Java does implicit casting during
- assignment
- method invocation.

For examples and more details, refer to the following tutorial
Java Tutorial

No comments: