This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The JVM maintains a pool of Strings, so that frequently used values can be reused instead of being instantiated all over again. In the following code, the two string variables refer to the same String instance:
Strings a and b are both literals. Their values are assigned explicitly rather than through the use of a constructor. If you assign a String using the new keyword, that value does not get added to the String pool. A new String instance is always created. It gets created even if that String value already exists in the pool and could have been used instead.
String c is NOT the same instance as Strings a and b.
It's almost always preferable to use literals instead of the String constructor.