• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange answers about "Strings" by JAMIE JAWORSKI

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have got confused by the answers to the exercise questions in the book of JAMIE JAWORSKI at the end of the chapter explaining Strings and String Buffer.
Q5- (page 218)
Which of the following methods cause the String object referenced by s to be changed ?
A- s.concat()
B- s.toUpperCase()
C- s.replace()
D- s.valueOf()
And the answer given is A & B. With the explanation that "The toUpperCase() and concat() change their associated String Objects.
While when i put them in codes and run, the original String is returned and that is not changed untill we assign like
s = s.concat()
What is the problem here ?
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fawad Khan,
The answer is wrong String Objects are immutable So no methods can modify the String Objects.
Siva
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree: concat, toUpperCase and replace all return new String objects. As do all the overloaded implementations of valueOf, but they are static methods, so have to be called by String.valueOf(primitive |Object )and not s.valueOf().
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fawad,
Which book edition are you using? In the text I have, the question is:

And the correct answer given is:


------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jane
This question is from
1999 First Indain Edition
Naveed
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Naveed,
I've got the July 1999 Edition by New Riders Publishing.
Perhaps there's a type-0 in your edition ... I just checked his mock exam at http://www.jaworski.com/java/certification/ it uses the question I quoted with the correct answer as D. By coincidence it was the first question that popped up so I didn't have to dig! My lucky day
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited February 23, 2001).]
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic