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.