Professional Documents
Culture Documents
Introduction
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Wrapper Class
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Wrapper Class
byte
Byte
short
Short
int
Integer
long
Long
char
Character
float
Float
double
Double
boolean
Boolean
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Wrapper classes are used to be able to use the primitive datatypes as objects.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
There are three reasons that we might use a Number object rather
than a primitive:
Integer x, y;
x = 12; y = 15;
System.out.println(x+y);
When x and y are assigned integer values, the compiler boxes the integers
because x and y are integer objects.
In the println() statement, x and y are unboxed so that they can be added as
integers.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example:
int a = 10; System.out.println(a.floatValue());
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
parseInt()
parseFloat()
parseDouble()
parseLong()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example:
public static String toString (int a)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example:
Integer i = Integer.valueOf (135);
Double d = Double.valueOf (13.5);
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
All of the numeric type wrappers inherit the abstract class Number.
Number declares methods that return the value of an object in each of the
different number formats. These methods are shown here:
byte byteValue( )
double doubleValue( )
float floatValue( )
int intValue( )
long longValue( )
short shortValue( )
Integer Class
Constructors:
Class Methods:
byteValue()
floatValue()
intValue()
longValue()
shortValue()
toString()
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Character Class
Boolean Class
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)