Hi,
First case you are creating two strings a,b with same value. First string "hi" will be created and 'a' will hold its reference and second time when you are creating string 'b' with the same value it just return reference of string "hi". Both a and b are referring to the same object.
Second case substring(0,2) method creates new string object that is why a==b will return false.
regards,
Usha