Course Content

Course Content


Object Wrapper Class in Java

In our previous video we have seen that how Super keyword at Constructor level works with example. Now in this video we are going to learn about what are Object Wrapper Class in Java provided with suitable example.

A Object Wrapper Class in Java wraps around a data type and gives it an object appearance. The data type is required as an object, this object can be used.

Object Wrapper class in Java programming include methods to unwrap the object and give back the data type. Wrapper class in Java provides a mechanism to convert primitive into object and object into primitive.

There are many to uses with Object Wrapper class in Java language. They are :
1. To convert simple data types into objects, that is, to give object form to a data type; here constructors are used.
2. To convert strings into data types (known as parsing operations), here methods of type parseXXX() are used.

Autoboxing and unboxing feature converts primitive into object and object into primitive automatically. The automatic conversion of primitive into object is known as autoboxing and vice-versa unboxing in Java.

One of the eight classes of java.lang package are known as Wrapper class.

Primitive : boolean, Wrapper : Boolean
Primitive : char, Wrapper : Character
Primitive : byte, Wrapper : Byte
Primitive : short, Wrapper : Short
Primitive : int, Wrapper : Integer
Primitive : long, Wrapper : Long

Example :
public class Wrapper
public static void main (String args [])
int a=20;
Integer i=Integer.valueof (a); //converting int into Integer
Integer j=a; //autoboxing, now compiler will write Integer.valueof (a) internally
System.out.println (a+" "+i+" "+j);
Output :
20 20 20

Now we will see an example for Wrapper to primitive in Java.
public class Wrapper1
public static void main(String args[])
Integer a=new Integer(3);
int i=a.intValue();//converting Integer to int int j=a;
System.out.println(a+" "+i+" "+j);

So, this was Object Wrapper class in Java programming language. In our next video, we will see what are StringBuffer and StringBuilder Classes in Java language.


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere