File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a question about string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a question about string" Watch "a question about string" New topic
Author

a question about string

chang nanny
Greenhorn

Joined: Feb 15, 2004
Posts: 14
Hello,

Please look at the following code,

String x= new String("abc");

how objects are created?

Thanks.
Anuradha Shanmugam
Greenhorn

Joined: May 09, 2004
Posts: 8
Hi Chang,

Hope your question is not complete.

Anyway,

if your question is "how objects are created?" then the answer is when you use new keyword an instance to the String class is created in the heap.

if your question is "how many objects are created? " then the answer is 1

Regards,
Anu


Anuradha<br />(SCJP 1.4)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Anu check this out:
new String("abc") == "abc" returns false. So a new object is created which is different to the object "abc" residing in the string pool. So if this is the first time "abc" is used, then you could say two objects are created.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about string
 
Similar Threads
date format with MS Access database
How to convert byte array into string array?
Tech Word Game
WA #1.....word association
ResultSet to Array