always remember that
"==" determines whether the reference variables refer to the same object
i.e. if Type obj = new Type();
Type obj1;
obj1 = obj;
then both the reference variables refer to the same object Type(); isn't it?
now in our situation,
Integer i1 = 1000;
Integer i2 = 1000;
we have two different objects having two different reference variables, hence if (i1 != i2) then println statement gets executed
and remember that equals method checks for the content of the object
now here
the content is same i.e. 1000 and 1000
hence i1.equals(i2) is true hence the meaningfully equivalent gets executed
But there is something weird with
java, the equality depends upon the range of values we are providing
Read and remember following carefully :
Two instances of the wrapper objects Boolean, Byte, Character from \u0000 to \u007f and short and integer from -128 to 127 will always be == when their primitive values are same