Wrapper classes in Java are : Integer,Character,Boolean,Float,Double,Long,Short and Byte.

Don’t get confused in between Wrapper class and primitive data types ,remember in Wrapper class , Every wrapper class name start with CAPITAL letter for example : Boolean , here B is capital.

The process of converting primitive data type into Objects is called Wrapping

To declare an integer “rollNumber” holding the value 20, we can write as : int rollNumber=20;

The object representation of integer “rollNumber” holding value 20 will be :

Integer integerObject =new Integer(rollNumber);

Here , class Integer is the wrapper class wrapping a primitive data type rollNumber

The process of converting the object into primitive type is called as Unwrapping.

int rollNumber= integerObject.intValue();

The Integer Class :

Integer class is a wrapper for values of type int.

Integer objects can be constructed with int value , or string containing an int value.

The Constructors of Integer :

Integer(int num)

Integer(String str) throws NumberFormatException

some methods of the Integer class :

static int parseInt(String val) throws NumberFormatException

int intValue() return the value of the invoking object as an int value.

The Character class :

Character class is a wrapper for char data types.

Constructor of Character class :

Character(char a) : here a specifies the character to be wrapped by the Character object

once character object is created you can retrieve primitive character value from it using :

char charValue()

The Boolean Class

The Boolean class is a wrapper class for boolean type values.

It has following Constructors :

Boolean(boolean value) : here value can be either true or false.

Boolean(String str): here , str can be “true” or “false” , it can be upper case or lower case.

The Float class

Float class is a wrapper class for floating point values of type float.

Float objects can be constructed with a float value,or a String containing floating point value.

The constructor of Float class are :

Float(float num)

Float(String value) throws NumberFormatException

some methods of Float class :

static Float valueOf(String val) throws NumberFormatException

float floatValue() return the value of invoking object as a float value.

The Double Class

Class Double is a wrapper class for floating-point values of type double.

Double class object can be constructed with a double value, or a string containing a floating-point value.

The constructors for double are shown here :

Double(double num)

Double(String val) throws NumberFormatException

some methods of Double class :

static Double valueOf(String str) throws NumberFormatException

double doubleValue() return the value of invoking object as a double value.

The Long Class

Class Long is a wrapper class for values of type long.

Long class object can be constructed with a long value, or a string containing a long type value.

The constructors for Long are shown here :

Long(long num)

Long(String val) throws NumberFormatException

some methods of Long class :

static Long valueOf(String str) throws NumberFormatException

long longValue() return the value of invoking object as a long value.

The Short Class

Class Short is a wrapper class for values of type short.

Short class object can be constructed with a short value, or a string containing a short type value.

The constructors for Short are shown here :

Short(short num)

Short(String val) throws NumberFormatException

some methods of Short class :

static Short valueOf(String str) throws NumberFormatException

Short shortValue() return the value of invoking object as a short value.

The Byte Class

Class Byte is a wrapper class for values of type byte.

Byte class object can be constructed with a byte value, or a string containing a long type value.

The constructors for Byte are shown here :

Byte(byte num)

Byte(String val) throws NumberFormatException

some methods of Byte class :

static Byte valueOf(String str) throws NumberFormatException

Byte byteValue() return the value of invoking object as a Byte value.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top