English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Each Java primitive data type has a class dedicated to it. These classes wrap the primitive data types into objects of the class. Therefore, they are called wrapper classes.
The following program displays the primitive data types in wrapper objects.
public class Demo { public static void main(String[] args) { Boolean myBoolean = new Boolean(true); boolean val1 = myBoolean.booleanValue(); System.out.println(val1); Character myChar = new Character('a'); char val2 = myChar.charValue(); System.out.println(val2); Short myShort = new Short((short) 654); short val3 = myShort.shortValue(); System.out.println(val3); Integer myInt = new Integer(878); int val4 = myInt.intValue(); System.out.println(val4); Long myLong = new Long(956L); long val5 = myLong.longValue(); System.out.println(val5); Float myFloat = new Float(10.4F); float val6 = myFloat.floatValue(); System.out.println(val6); Double myDouble = new Double(12.3D); double val7 = myDouble.doubleValue(); System.out.println(val7); } }
Output Result
True a 654 878 956 10.4 12.3
In the above program, we have handled each data type one by one. You can see an example is the boolean value. Our wrappers are-
Boolean myBoolean = new Boolean(true);
Now, the primitive data types are wrapped in wrapper objects.
boolean val1 = myBoolean.booleanValue();