Wrapper Classes
Java Wrapper Classes :
In object oriented programming, a wrapper class is a class that encapsulates types, so that those types can be used to create object instances and methods in another class that need those types. So a primitive wrapper class is a wrapper class that encapsulates, hides or wraps data types from the eight primitive data types.- Provides a way of wrapping primitive values in an object so that a primitive can be treated as an object.
- Provides a set of utility methods for primitives.
- Wrapper classes are available in java.lang package.
- When primitives are required to be added to a collection object.
- When we want to return a primitive from a method that returns an object.
- When converting primitives to and from String objects.
- When converting primitives & String objects to and from different bases like binary, octal & hexadecimal.

Object Creation:
Integer i1 = new Integer(5); Integer i2 = new Integer("5"); Float f1 = new Float(5.6f); Float f2 = new Float("5.6f"); Double d1 = new Double(6.7); Double d2 = new Double("6.7"); Character c = new Character('a'); Boolean b1 = new Boolean(true); Boolean b2 = new Boolean("true"); Boolean b3 = new Boolean("TrUe");Methods:
parseInt(s) returns a signed numeric value equivalent to string s valueOf(primitive) returns wrapper object equivalent to primitive valueOf(String) returns wrapper object equivalent to String valueOf(String,int) returns wrapper object equivalent to String as per give base(DEC-10,BIN-2,OCT-8,HEX-16) value. toString(i) returns a new String object representing the integer i byteValue() returns the value of this type as a byte doubleValue() returns the value of this type as a double floatValue() returns the value of this type as a float intValue() returns the value of this type as an int shortValue() returns the value of this type as a short longValue() returns the value of this type as a longExample:
class Test { public static void main(String[] a) { String s = "A"; Integer i1 = Integer.valueOf(s,16); byte b = i1.byteValue(); System.out.println(b); } }
10
Next topic is generics
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at info@prowessapps.in
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at info@prowessapps.in