Compile-time string expressions are put into the String pool.
s=s+"JVM" is not a compile-time constant expression. so everytime it creates a new string object in heap.

for more details see this https://stackoverflow.com/questions/16729045/behavior-of-string-literals-is-confusing