Learn Java Programming - Primitive Wrapper Classes Tutorial

Pubblicato il: 31 agosto 2015
sul canale di: 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.


In questa pagina del sito puoi guardare il video online Learn Java Programming - Primitive Wrapper Classes Tutorial della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Daniel Ross 31 agosto 2015, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 4,988 volte e gli è piaciuto 40 spettatori. Buona visione!