aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How many objects are created? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How many objects are created?" Watch "How many objects are created?" New topic
Author

How many objects are created?

Patricia Anderson
Greenhorn

Joined: Jun 15, 2001
Posts: 24

String s = new String("crispy");
Q: How many objects are created?
/***********************************/
String s = new Sring ("creme");
String w = "creme";
Q: How many objects are created?
/***********************************/
StringBuffer s = new StringBuffer("CrispyCreme");
String s = "CrispyCreme";
Q: How many objects are created?
Ravi Mann
Greenhorn

Joined: Jun 29, 2001
Posts: 8
2, 2, 2
Gokhan Gultekin
Greenhorn

Joined: Jun 23, 2001
Posts: 27
The same question has been discussed many times in this forum.
Ravi's anwser is correct..
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Patricia

Two. A string literal object "crispy" created in the string pool and a String Object in regular memory containing the characters "crispy"

Two. A string literal "creme" created in the string pool. A String object in regular memory containing the characters "creme". 'w' will point to the existing string literal object which contains the same characters "creme"

Two. Same reason as above for "creme"
Whenever you see a string literal ie a string of characters in double quotes; a String literal will be created in the pool if one doesn't already exist.
The 'new' operator always creates a unique string object in regular memory.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Patricia Anderson
Greenhorn

Joined: Jun 15, 2001
Posts: 24
Gee thanks everyone for your input. I felt i needed to ask simple straightforward questions -- after going through two mock exams.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How many objects are created?
 
Similar Threads
number of objects created
Object creation??
How many Objects are created ?
How many objects ?
StringBuffer Question.