This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I need the difference between string s="abc" and string s=new string("abc");
How many objects created for both .
The following i got from google , is it correct.
String s "abc"; is the simple case it will create one string object and one reference variable. "abc" will go into the pool and s will refer to it...
String s new String("abc"); it will create two objects and one reference variable.
java will create a new string object in the nonpool memory s will refer to it. the literal "abc" will be placed in the pool.
If you want to really confirm the answer, you can put statements
string s="abc" and string s=new string("abc"); in main function of say Test.java and deassemble the code using command
javap -c Test. It will show you the details.
Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )