File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String literal vs String object" Watch "String literal vs String object" New topic

String literal vs String object

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 980
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.

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).

A Kumar
Ranch Hand

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

I found an interesting link too which offers further explanation

Thanks & have a nice time,
I agree. Here's the link:
subject: String literal vs String object
It's not a secret anymore!