Number Class

All numeric wrapper classes are child class of Number class. All numeric wrapper classes has two type of constructors one with their corresponding primitive data type and another with String.

Constructor for Byte class :

   
	   Byte(byte b)
OR
Byte(String s)


Methods of Number Class

Method Description
byte byteValue() Returns value of this object as byte primitive data type.
short shortValue() Returns value of this object as short primitive data type.
int intValue() Returns value of this object as int primitive data type.
long longValue() Returns value of this object as long primitive data type.
float floatValue() Returns value of this object as float primitive data type.
double byteValue() Returns value of this object as double primitive data type.
int compareTo(Byte b) Compare this object with specified obejct.
int compareTo(Short b)
int compareTo(Integer b)
int compareTo(Long b)
int compareTo(Float b)
int compareTo(Double b)



Useful methods of Integer class for Number system Conversion

Method Description
static String toBinaryString(int i) Returns binary equivalent string of specified integer.
static String toHexString(int i) Returns hexa equivalent string of specified integer.
static String toOctalString(int i) Returns octal equivalent string of specified integer.
static String toString(int i) Returns String object with value of specified integer.
static String toString(int i, int r) Returns String object having value of specified integer 'i' on radix 'r'.



Examples

Exmaple: Convert Byte object into byte primitive type




class conv 
{
public static void main(String arg[])
{
Byte b=new Byte(120);
byte c;

c=b.byteValue();// Byte object to primitive data type
System.out.println(c);

}
}
/* Output:
120
*/

Exmaple: Convert int variable into binary, hex and octal



class conv 
{
public static void main(String arg[])
{
int a=120;
// Number conversion

System.out.println("Binary:"+Integer.toBinaryString(a));
System.out.println("Hexa:"+Integer.toHexString(a));
System.out.println("Octal:"+Integer.toOctalString(a));
}
}