Class 10 ICSE - Java

Wrapper Class

Defination



As the name suggest wrapper,in simple words it means that it will wrap primitive datatype to wrapper class object.It belongs to java.lang package

These primitive datatypes are predefined datatypes basically used to store different types of values like:

int-to store integer
char-to store character
double-to store decimal value
and so on.It has no additional methods to perform.

When we talk about primitive class object,each primitive datatype has its own wrapper class,these classes converts the primitive datatype into object of that class.Example Integer class can wrap a int variable,Double class can wrap a double variable,etc.

These wrapper classes, provide some features that is:-
  1. To wrap the primitive datatye to class object
  2. It allow primitive datatype to convert from one type to another type.For example,converting string to integer type.
  3. It will provide some methods to primitive datatypes,which are reserved for the wrapper class object,like hashcode.


The list of 8 wrapper class for primitive datatypes are given below:-



Difference in wrapper class object and primitive datatype



Let us know the difference between primitive datatype and wrapper class object by an example:-





In the above program, there is no major difference between a normal variable and primitive class object as output of both of them is same. But when this line is executing that is:-

int i=7;

It will be represented as a normal int datatype variable which is holding value as 7.It has no additional methods to perform.
When this line is executing that is:-

Integer j=8;

It will be represented as object of class Integer which contain value as 8.In this object we can various methods such as:-

  1. It can be converted from on type to another type.
  2. Arraylist
  3. Linkedlist
  4. Treeset
and many more.

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com