Wrapper classes in java

Previous
Next

Primitive types:

  • Java supports 8 primitive data types.
  • Java is not Fully Object oriented programming language
  • Any language that supports primitive types is not Fully Object oriented.
  • Examples of Fully OOPLs: Python, Small talk, Ruby…..

Wrapper classes:

  • Wrapper classes are pre-defined.
  • For every primitive type there is a corresponding wrapper class.
  • Wrapper classes providing functionality by which we can perform data conversions.
  • Using wrapper classes, we can convert the primitive data into Object.
  • We can define Fully Object Oriented java application using Wrapping.

Hierarchy:

  • Wrapper classes belong to lang package.
  • Wrapper classes are Childs to Object class.
  • Some of the wrapper class are direct extensions of Object such as Number, Character and Boolean.
  • All other classes are the Childs of Number class such as Byte, Short, Integer….

Functionality of Wrapper classes:

  1. Data conversions
  2. Fields – To find limits and size of data types

Wrapper classes are mainly used to perform following data conversions.          

  1. Primitive to Object (Boxing)
  2. Object to Primitive (UN boxing)
  3. Primitive to String
  4. String to Primitive
  5. Object to String
  6. String to Object

Note: These are common methods in every wrapper class. Conversions are similar in different wrapper classes.

Previous
Next

Add Comment

Courses Enquiry Form