Sindhur, Welcome to JavaRanch. The reason is that in the case of b and b1, you are actually assigning them to the same object which is a public static final field in the Boolean class. In the case of b2 and b3, you are actually creating 2 new objects which have equal value but do not occupy the same memory space. See the explanation in the Javadoc. [ February 26, 2004: Message edited by: Ken Krebs ]
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Hi Sindhur: Your doubt stems from confusion regarding functioning of == and the .equals() method of the object. Lets start with ==. When we use ==, to compare 2 references, we are testing if both are pointing at the same object. In your case b2 and b3 are pointing to 2 different objects hence it returns false. next in case of .equals() this method compares the values contained in the object. In case of the wrapper classses (String, Integer, Boolean...) it has been implemented to compare the contents of the objects. so b2.equals(b3) will return true since both b2 and b3 both contain the value true.
Next, Boolean.valueOf() is a static method that returns the static variable Boolean.TRUE or Boolean.FALSE. Only 1 copy of these variables exists for the Boolean class. So all the Boolean objects created using the Boolean.valueOf() methods will point to either of these static objects. hence b==b1 will be true and b.equals(b1) will be true.