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.
The moose likes Beginning Java and the fly likes String literal vs String object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String literal vs String object" Watch "String literal vs String object" New topic
Author

String literal vs String object

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Can u please tell me whats is the difference between a string literal & string object...

because i thought that any instnance of string is an object.

String name="XYZ";
String name1=new String("hjhj");


Thanks in advance.

ArKumar
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
A String literal lives in the String object pool, if you create a String object using the new operator it lives on the heap (while you in your example also create a String literal in the String object pool).


42
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thank you my dear friend..

I found an interesting link too which offers further explanation


http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html


Thanks & have a nice time,
Aneesh.
 
Consider Paul's rocket mass heater.
 
subject: String literal vs String object