Pages

How to create object from primitive data type ???

***************************************************************************
COMPLETE SOURCE CODE FOR : CreateObjectFromPrimitiveDataType.java
***************************************************************************


public class CreateObjectFromPrimitiveDataType
{
public static void main(String[]args)
{
//PRIMITIVE TYPE : boolean
boolean a=true;
Boolean booleanObject=new Boolean(a);//CREATE OBJECT FROM a

//PRIMITIVE TYPE : byte
byte b=(byte)9;
Byte byteObject=new Byte(b);

//PRIMITIVE TYPE : char
char c='a';
Character charObject=new Character(c);

//PRIMITIVE TYPE : short
short d=(short)9;
Short shortObject=new Short(d);

//PRIMITIVE TYPE : integer
int e=9;
Integer intObject=new Integer(e);

//PRIMITIVE TYPE : long
long f=9L;
Long longObject=new Long(f);

//PRIMITIVE TYPE : float
float g=9.9F;
Float floatObject=new Float(g);

//PRIMITIVE TYPE : double
double h=9.9D;
Double doubleObject=new Double(h);

//PRINT VALUE FOR EACH OBJECT
System.out.println("VALUE FOR BOOLEAN : "+booleanObject.booleanValue());
System.out.println("VALUE FOR BYTE : "+byteObject.byteValue());
System.out.println("VALUE FOR CHARACTER : "+charObject.charValue());
System.out.println("VALUE FOR SHORT: "+shortObject.shortValue());
System.out.println("VALUE FOR INTEGER: "+intObject.intValue());
System.out.println("VALUE FOR LONG : "+longObject.longValue());
System.out.println("VALUE FOR FLOAT : "+floatObject.floatValue());
System.out.println("VALUE FOR DOUBLE: "+doubleObject.doubleValue());
}
}


***************************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************************
Related Posts Plugin for WordPress, Blogger...

I Also Can Create T-Shirt Logo For You