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 Programmer Certification (SCJP/OCPJP) and the fly likes how many objects are created by this statement 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how many objects are created by this statement" Watch "how many objects are created by this statement" New topic
Author

how many objects are created by this statement

Saravanakumar Rajmohan
Greenhorn

Joined: Jul 08, 2003
Posts: 17
how many objects are created by this statement?
System.out.println( "Hi everyone" + 3 );
String object representing "Hi everyone"
Wrapper object for representing the primtive value 3(is this required ?)
String object representing the value 3
String object representing "Hi everyone3"
is this correct or will this undergo optimisation(will it involve StringBuffer)? .
will this have a constant behavior in all JVM implementations
can somebody explain this
thank u
Saravanakumar R
Calvin Yan
Greenhorn

Joined: Jun 25, 2003
Posts: 19
Hi
I think the created objects should include "Hi everyone" and "Hi everyone3"


I will do the best with what God gave me!
Ted Smith
Greenhorn

Joined: Jul 20, 2003
Posts: 3
In this scenario, Two objects was created,
1. "Hi everyone"
2. "Hi everyone3"
Wrapper object is not needed in this case. The concatenation method of String class can accept an integer primitive.
sherry cuenco
Greenhorn

Joined: May 07, 2003
Posts: 24
I think there are three objects created.
1 "Hi everyone"
2 "3" // Java converts int 3 to a String
3 "Hi everyone3"
 
Don't get me started about those stupid light bulbs.
 
subject: how many objects are created by this statement
 
Similar Threads
valueOf
String new object clarification
i'm bit curious about the concatenated string literals with +
strings, string pool and garbage collection
what is the diff? (Strings again)