i1,i2 will point to same reference. Because JVM maintains a constant pool for wrapper objects just like it does for Strings. Hence i1 and i2 will point to the same reference in the constant pool. And i3,i4 will point to the same memory in the constant pool
Sanjeev, That range of -128 to 127 is applicable to Byte, Short and Integer. Then what is the valid range for Long? And also please let me know how did you get access to the code of Integer.valueOf() method ?
Joined: Feb 08, 2006
I just downloaded JDK 1.5 Source code from Sun site. When i peeped into the Byte, Short, Integer, Long source code the range was -128 to 127
For Character the range is for anything less than <=127
But for Float, Double no caching is provided. That is
Float f1=3.0F; Float f2=3.0F; System.out.println(f1==f2); will produce false