In: Computer Science
Why do you think Java provides both primitive data types and wrapper classes for them? Why not just one or the other?
Java provides both primitive data types and wrapper classes.java being object-oriented in nature and expects everything in the form of an objects . so Primitive datatypes are converted into objects by using Wrapper classes.
A Wrapper class is a class whose object wraps or contains a primitive data types.
When we create a wrapper class object , it contains a field and in this field and can store a primitive data types. In other words, we can wrap a primitive value into a wrapper class object.
The following picture shows both primitive data types and wrapper classes.
Need of Wrapper Classes: