As Strings are immutable, when you do:
String a = "xyz"
while creating the string, the JVM searches in the pool of strings if there already exists a string value "xyz"
, if so 'a'
will simply be a reference of that string and no new String object is created.
But if you say:
String a = new String("xyz")
you force JVM to create a new String
reference, even if "xyz"
is in its pool.
For more information read this.