Java Wrapper Classes

Let’s start with an interesting question. Is java pure object oriented? You have heard about object oriented programming but what is “pure” object oriented?. In Pure Object Oriented programming languages every variable is an object, and every “operator” is a method. So, by this definition, is java pure object oriented?

The answer is NO. But why?

Because java supports primitive data types such is int, long, float, double etc which are not objects. So how to convert these primitive data types to objetcs? That’s where Java wrapper classes come into the picture.

Wrapper classes

The wrapper classes in the Java provides a way to “wrap” primitive values to an object. Each primitive type has its corresponding wrapper class. Please note that primitive type is all lowercase while its wrapper “class” starts with upper case.

Below are the primitive types and their wrapper classes

Primitive

Wrapper class

boolean Boolean
byte Byte
char Character
double Double
float Float
int Integer
long Long
short Short

 

Note

  • Wrapper classes are final.

  • Wrapper classes are immutable.

Leave a Reply

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