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 String Objects 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 "String Objects" Watch "String Objects" New topic
Author

String Objects

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 165
Respected Sirs,

public String makeStrings()
{
String s="Fred";
s=s+"47";
s=s.substring(2,5);
s=s.toUpperCase();
return s.toString();
}
/*How many string objects will be created when this method is invoked
a)1
b)2
c)3
d)4
e)5
f)6

Thnks

Francis
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Total Five String referential objects?


Thanks & Regards
Sidharth Pallai
francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 165
But the question providers say the answer is 3:

I think there is 6:

1) "Fred"
2) "47"
3)"Fred47"
4)"ed4"
5)"ED4"
6)"ED4" , while calling toString()

can anyone help with explabation
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Try searching the forums for "Fred 47". This exact same question has been asked and answered here many times.

For example:
How many string object created in this code
String Test
Strings
Q from javaBeat on String
Strings Doubt
Strings
doubt with string abjects
How many object create?
...
[ July 01, 2008: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Sunny Mattas
Ranch Hand

Joined: Apr 22, 2008
Posts: 45
Read questiobnm carefully
It ask's for number of strings objects created when method is invoked i.e. at runtime.
I think there are three string objects being created when program runs. Others are created at compile time.

Regards
Sunny


Regards
Sunny Mattas
SCJP5
Madhukar Ojha
Ranch Hand

Joined: Mar 21, 2007
Posts: 71
Hi Rancher ,

Total 3 String objects will be created .
"Fred" and "47" are literals hence will be created before invocation of this method.


SCJP 5 ๑۩۞۩๑♥~~ My Life is My Creation ~~♥๑۩۞۩๑
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Objects
 
Similar Threads
String Objects...
How many String objects will be created?
how many String objects created??
How many String objects are created?
please provide the explanation regarding string objects............