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.
String s = "abc"; //Creates one string object and one ref. var. In this simple case, "abc" will go to the pool and s will refer to it.
String s = new String("abc"); //Creates two objects, and one ref var. In this case, because we used the new keyword, Java will create a new String object in normal(non-pool) memory, and s will refer to it. In addition, the literal "abc" will be placed.
Why two objects are created in the second case? Still don't understand why the two cases are working differently. Plus, the second case looks like more inefficient.
In second case if i say: String s1 = s; Would s1 refer to the intermediate object pointed to by s or directly to "abc".