• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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).]
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic