Learn Java Programming - Primitive Wrapper Classes Tutorial

Опубликовано: 31 Август 2015
на канале: Daniel Ross
4,988
40

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.


На этой странице сайта вы можете посмотреть видео онлайн Learn Java Programming - Primitive Wrapper Classes Tutorial длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Daniel Ross 31 Август 2015, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 4,988 раз и оно понравилось 40 зрителям. Приятного просмотра!