Java-Primitive Wrapper Classes

Primitive Wrapper Classes

Primitive data types may be converted into object types by using the wrapper classes. These wrapper classes are available in the java.lang.package. So you can use them without an import statement. The eight wrapper classes are named in the following table.

Primitive Data Type Wrapper Class
boolean Boolean
byte Byte
char Character
short Short
int Integer
long Long
float Float
double Double

These wrapper classes encapsulate (or) “wraps up” a primitive type. So that a variable can be represented by an object when necessary. These classes also have a constants MAX_VALUE and MIN_VALUE.

Program

0

Program Source

public class Javaapp {

    public static void main(String[] args) {
        
        Byte data1 = new Byte((byte)10);
        Byte data2 = new Byte("110");
        
        Short data3 = new Short((short)2000);
        Short data4 = new Short("2500");
        
        Character data5 = new Character('Q');
        
        Integer data6 = new Integer(10000);
        Integer data7 = new Integer("20000");
        
        Boolean bool1 = new Boolean(true);
        Boolean bool2 = new Boolean("false");
        
        System.out.println("data1 = "+data1);
        System.out.println("data2 = "+data2);
        System.out.println("data3 = "+data3);
        System.out.println("data4 = "+data4);
        System.out.println("data5 = "+data5);
        System.out.println("data6 = "+data6);
        System.out.println("data7 = "+data7);
        System.out.println("bool1 = "+bool1);
        System.out.println("bool2 = "+bool2); 
    }
}

Leave a Comment