There are eight basic data types in java, which correspond to eight packaging types. Below are the eight data primitive types and their corresponding wrapper types.
No. | basic data type | type of packaging |
---|---|---|
1 | long | Long |
2 | int | Integer |
3 | short | Long |
4 | byte | Byte |
5 | float | Float |
6 | double | Double |
7 | string | String |
8 | boolean | Boolean |
When it comes to the conversion of primitive types and wrapper types, the concepts of boxing and unboxing are mentioned.
Boxing
Converts a data primitive type to a wrapper type and gives it the properties of an object. Packing is also divided into manual packing and automatic packing.
- Manual boxing
int a = 10;
Integer b = new Integer(a);
- autoboxing
int a = 10;
Integer b = a;
Unboxing
Converts the data's wrapper type to the data's base type. Unpacking is also divided into automatic unpacking and manual unpacking.
- Manual unboxing
Integer a = new Integer(10);
int b = a.valueOf(a);
- Automatic unboxing
int b = a;