Tuesday, March 3, 2009

autoboxing autounboxing issues



/* 1. By using autoboxing. If it is required to create a new wrapper object, the compiler won’t create any new object, if already an object is
present in the fallowing cases.Boolean and Byte.For the integer and short
if the value is less than or equal to 127.For the long of the value is
less than or equal to 127 l.Character object ranges from 0 to 127 */



class Scases
{
public static void main(String arg[])
{
Integer I1= 10;
Integer I2= 10;
System.out.println(I1==I2); //true
Integer I3= new Integer(10);
System.out.println(I1==I3); //false
Integer I4= 127;
Integer I5= 127;
System.out.println(I4==I5); //true
Integer I6= 128;
Integer I7= 128;
System.out.println(I6==I7); //false

//Similarly
Short s1=127;
Short s2=127;
System.out.println(s1==s2); //true

Short s3=128;
Short s4=128;
System.out.println(s3==s4); //false

Long l1=300l;
Long l2=300l;
System.out.println(l1==l2); //false
}
}


0 comments:

Post a Comment