The main objectives of wrapper classes are:

  1. To Wrap primitives into object form. So that we can handle primitives also just like objects.
  2. To Define several utility functions for the primitives(like converting primitive to the string form etc.

Constructors:

  1. valueOf()
  2. xxxValue()
  3. parseXxx()
  4. toString()

Constructing Wrapper objects by using constructors
Every Wrapper class contains 2 constructors one can take the corresponding primitive as the argument and the other can take the corresponding string as the argument.

  1. Integer class

    Example:

    public class Demo {
    
        public static void main(String args[]) {
    
            Integer I = new Integer(10);
            Integer I1 = new Integer("10");
            System.out.println(I);
            System.out.println(I1);
        }
    }
    /*
    output:
    10
    10*/
    

    Note:If the String is unable to convert into the number form then we will get run time exception saying “NumberFormatException“.
    Example:

    public class Demo {
    
        public static void main(String args[]) {
    
            
            Integer I1 = new Integer("ten");
            
            System.out.println(I1);
        }
    }
    /*
    NumberformatException
    */
    
  2. Float class
    This class contains 2 constructors which can take double String as argument.
    Example:

    public class Demo {
    
        public static void main(String args[]) {
    
            Float f = new Float(10.5f);
            Float f1 = new Float("10.5f");
            Float f2 = new Float(10.5);
            Float f3 = new Float(10.5);
    
            System.out.println(f);
            System.out.println(f1);
            System.out.println(f2);
            System.out.println(f3);
        }
    }
    /*
    10.5
    10.5
    10.5
    10.5
    */
    
  3. Character class
    This class contain only one constructor which can take char as the argument i.e character class doesn’t contain a constructor which can take string as the argument.

    Example:

    public class Demo {
    
        public static void main(String args[]) {
    Character ch1 = new Character('a'); // valid.
    Character ch1 = new Character("a"); // not valid.
    }
    }
    
    
  4. Boolean class
    1. This class contains 2 constructors one can take boolean primitive. Other can take string argument. If you are providing boolean primitive as the argument the. The allowed values are true or false.
    2. Case is not important if the content contains ‘TRUE’ then it is considered as true other wise it considered as false.

    Example:

    public class Demo {
    
        public static void main(String args[]) {
    
    Boolean b = new Boolean(true); //true
    Boolean b = new Boolean(FALSE);//not valid
    Boolean b = new Boolean("false");//false
    Boolean b = new Boolean("TrUE"); //true
    Boolean b = new Boolean("raju"); //false
    Boolean b = new Boolean("yes");//false
    }
    }
    

    Example

    public class Demo {
    
        public static void main(String args[]) {
    
    Boolean b1 = new Boolean("yes");
    Boolean b2 = new Boolean("No");
    System.out.println(b1.equals(b2));
    }
    }
    /*output:
    true*/
    
WrapperClasses constructor arguments
Byte byte (or) string
Short short (or) string
Integer int (or) string
Long long (or) string
Float float (or) string (or) double
Double double (or) string
Character char
Boolean boolean (or) string

valueOf method:

version1:

All the wrapper classes except Character class contains the valueOf() method for converting string to corresponding Wrapper Object.

public static wrapper valueOf(String s);
Example:

public class Demo {

    public static void main(String args[]) {
Integer I = Integer.valueOf(‘10’);//10
Float F = Float.valueOf("10.5");//10.5
Boolean B = Boolean.valueOf("java");//false
Character ch = Character.valueOf(“10”);//invalid
}
}

Version2:

All Integral wrapper classes “Byte, Short, Long, Integer” Contains the following valueOf() method.
public static wrapper valueOf(String s, int radix);
The allowed base of radix is 1 to 36.Because Numerics(10) ,Alphabets(26) finally 10+26 =36
Example:

public class Demo {

public static void main(String args[]) {
Integer I = Integer.valueOf("101011", 2);
System.out.println(I);
}
}
/*output:
43*/

Version3:

Every Wrapper class including character class contains the following valueOf() method to convert primitive to wrapper object form.

public static wrapper valueOf(primitive p);
Example:

public class Demo {

public static void main(String args[]) {
Integer I = Integer.valueOf(10);
Character ch = Character.valueOf('a');
Boolean B = Boolean.valueOf(true);
}
}
/*output:
10
a
true
*/

According to Above scenario

Version 1, Version 2 String to wrapper object.
Version 3 primitive to wrapper object.

xxxValue() method

Every wrapper class Except character and Boolean classes contains the following xxxValue() methods for converting wrapperObject to primitive.

public int intValue();
public byte byteValue();
public short shortValue();
public long longValue();
public float floatValue();
public int doubleValue();

Example:

public class Demo {

public static void main(String args[]) {
Integer I = Integer.valueOf(130);
        System.out.println(I.byteValue());
        System.out.println(I.shortValue()); 
        System.out.println(I.intValue()); 
        System.out.println(I.longValue());
        System.out.println(I.floatValue());
        System.out.println(I.doubleValue());
    }
}
/*output:
-126
130
130
130
130.0
130.0*/

Character class contain charValue() method to return char primitive for the given character wrapper object.

public char charValue();
Example:

public class Demo {

public static void main(String args[]) {
Character ch = new Character('a');
char ch1 = ch.charValue();
System.out.println(ch1);
}
}
/*output:
a*/

Boolean class contains booleanValue() method to return boolean primitive for the given boolean objective.
Example:

public class Demo {

public static void main(String args[]) {
Boolean B = Boolean.valueOf("MNC");
boolean b1 = B.booleanValue();
System.out.println(b1);

}
}
/*output:
false*/

Note:
In total 38 xxxValue methods are possible ((6 X 6) +1 + 1) = 38