Wednesday 23 August 2017

wrapper class in java

why we need wrapper class?

Java is an object oriented language and can view everything as an object. A simple file can be treated as an object, an address of a system can be seen as an object.

"wrapper can be used to convert any data type into object"

The primitive data types are not object they do not belongs to any class they are defined in the language itself that's why Java is not
called pure object oriented programming language. Sometimes it require to convert data type into object. Datatype converted into an object and then added to a stack or vector.

what are wrapper class?

A wrapper class wraps(encloses) around a datatypes and given it an object appearance. wherever as an object, this object can be used wrapper classes include method to unwrap the object and give back the data type.

int k = 100;
Integer it = new Integer(k)
you can also unwrap-
int m = it.intvalue();

Importance of wrapper classes:

  1. To convert simple data types into objects, that is, to give object form to a data type here constructor are used.
  2. To convert string into data types (parsing) here method of type parse**() are used.T
  3. The valueOf() method is available in all wrapper classes except character.
  4. All wrapper classes have typeValue() method. 
Write your comment and suggestion.

learn code !!

No comments:

Post a Comment