Classes Are Used.: Number Class
Classes Are Used.: Number Class
.lang package There are cases where instances of these classes are used instead of the primitives(int, float, double..) For this purpose wrapper classes are used. All of the wrapper classes are sub-classes of the number class. 3 Situations where Number object is used rather than a primitive: 1. As an argument of a method that expects an object (often used when manipulating collections of numbers). 2. To use constants defined by the class, such as MIN_VALUE and MAX_VALUE, that provide the upper and lower bounds of the data type. 3. To use class methods for converting values to and from other primitive types, for converting to and from strings, and for converting between number systems (decimal, octal, hexadecimal, binary). WRAPPER CLASS : They wrap the primitive into an object. As per the need, the wrapping(auto-boxing) & unwrapping(unboxing) is done automatically by the compiler. Eg : if a primitve is used when an object is expected, the compiler boxes the primitive in its wrapper class. And if an object is used instead of a primitve, the compiler unboxes the object to the primitve.
Primitive type Wrapper class boolean byte char float int long short Boolean Byte Character Float Integer Long Short