There are eight primitive data types in the Java language: byte, short, int, long, float, double, char, and boolean. Different rules apply to primitive types versus Object types and vice-versa. There are many occasions when we need to convert back a forth between object and primitive values and Java provides us the ability to do this via wrapper classes. What is a primitive wrapper class? The sole purpose of a wrapper class is to provide the ability to return a primitive data type from an object, or to provide an object from a primitive data type. The wrapper classes do this by using a combination of constructors and methods.
There is a wrapper class designed specifically for each and every one of the primitive data types: Byte, Short, Integer, Long, Float, Double, Character, and Boolean. Notice that the class name is identical – except the uppercase first letter – to the primitive data type on six of the eight classes, only Integer and Character differ in that respect. Each one of the eight wrapper classes has overloaded constructors and quite a few methods. I will be going into great detail on each individual wrapper class in future tutorials, but before I do so, I need to introduce you to the concept of boxing.
Boxing is the technical term for encapsulating a value within an object. Unboxing is the technical term for retrieving a value from an object. I'll demonstrate an example of a immutable class (all the primitive wrappers are immutable) that will box a primitive int into an object, then unbox it by invoking a method.
On this page of the site you can watch the video online Learn Java Programming - Primitive Wrapper Classes Tutorial with a duration of hours minute second in good quality, which was uploaded by the user Daniel Ross 31 August 2015, share the link with friends and acquaintances, this video has already been watched 4,988 times on youtube and it was liked by 40 viewers. Enjoy your viewing!