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:
- Data conversions
- Fields – To find limits and size of data types
Wrapper classes are mainly used to perform following data conversions.
- Primitive to Object (Boxing)
- Object to Primitive (UN boxing)
- Primitive to String
- String to Primitive
- Object to String
- String to Object
Note: These are common methods in every wrapper class. Conversions are similar in different wrapper classes.