0% found this document useful (0 votes)
28 views1 page

Classes Are Used.: Number Class

Number is a base class that all wrapper classes like Integer, Float, and Double inherit from. Wrapper classes wrap primitive types like int and float into objects to allow primitives to be used where objects are required, like in collections, or to access useful methods for converting between types and number systems. The compiler automatically boxes primitives into wrapper objects when objects are expected and unboxes objects back to primitives when primitives are expected.

Uploaded by

Jesvin Mathew
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

Classes Are Used.: Number Class

Number is a base class that all wrapper classes like Integer, Float, and Double inherit from. Wrapper classes wrap primitive types like int and float into objects to allow primitives to be used where objects are required, like in collections, or to access useful methods for converting between types and number systems. The compiler automatically boxes primitives into wrapper objects when objects are expected and unboxes objects back to primitives when primitives are expected.

Uploaded by

Jesvin Mathew
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Number Class : Present in the java.

.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

You might also like