File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String literal vs String object