This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Sting Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sting Classes" Watch "Sting Classes" New topic
Author

Sting Classes

rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159
String s= "REX";
String s= new String("REX");
Both are classes too.
what are the Main Key differences
Amgad Muhammad
Ranch Hand

Joined: Mar 26, 2008
Posts: 46
Originally posted by rex tony:
String s= "REX";
String s= new String("REX");
Both are classes too.
what are the Main Key differences


String s= "REX";

a string refrence s is created and a string with the REX value is created in the string pool.

String s= new String("REX");

a string refrence s is created and a string with the REX value is created in the string pool, and a String object is created in the heap.


SCJP5-(100%)
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
As an aside, there is only one class involved in your examples: java.lang.String. What you have several of are objects, all being instances of that single class.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sting Classes
 
Similar Threads
Constructor
Pet animal
Inner class
JAVA architecture
Boxing/Unboxing