what happens on equating two strings i.e. if sa and sb are two strings and statement is like
does the reference location of sb is assigned to sa
or value at reference location of sb is copied to reference location of sa.???
You first answer: "the reference location of sb is assigned to sa". And to be overly specific, you say "if sa and sb are two strings ". Actually sa and sb are reference variables of type String. These variables can point at different String instances, the same String instance, or no String instances at all (null).
Java behaves differently with string literals (e.g a="abc") when compared to creating a String object explicitly on the heap (e.g new String("abc")).
The difference is that the JVM operates a string constant pool (SCP) and any string literals are entered into the pool at load time.
a="abc"; will enter the "abc" into the SCP, then anywhere "abc" is referred, the reference will point to the same "abc" in the SCP.
a=new String("abc"); is explicitly creating a new string object with the value "abc". For this reason the top code block creates two different String objects, therefore a != b.
The bottom code block creates the String in the SCP after a="abc";, then when you do b="abc"; the JVM sees that string already exists in the SCP and refers b to it. Therefore a==b.
Also, further to the above, you will need to remember that a=new String("abc"); will create TWO string objects, first in the SCP (at load time, because it was created as a literal) and another one on the heap (being referred to by a), however, a will refer to the new object on the heap.