This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes difference K&B P:420 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "difference K&B P:420 " Watch "difference K&B P:420 " New topic
Author

difference K&B P:420

Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

In K&B P:420 it is given as

String s="abc";

String s=new String("abc");

And its said that these will create 2 objects and 1 reference

My Question is:
Since the two strings points to same content what is the need for creating two objects. Wont the string constant pool checks this.........


Thanks in Advance


Thanks, Shiv
SCJP, OCE - JSP & Servlets Developer
Pinkal Patel
Ranch Hand

Joined: Jun 16, 2006
Posts: 57
When you are using new String("123");

Will create unother Object without cheaking the Pool.


and when unig s="123";

It will first check pool and create object if it is not found in the Pool

May be this will clear your doubt.


Pinkal Patel<br />SCJP 1.5<br />Preparing for SCWCD
Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

Thanks Pinkal
 
GeeCON Prague 2014
 
subject: difference K&B P:420