• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Confusion about String equality (Sybex)  RSS feed

 
Ranch Hand
Posts: 30
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!  This question is not about the books but about the test bank that is provided as a resource with the purchase of the book.  I wish that Sybex would provide question discussion forums for each question, similar to Enthuware setup.  There is a question the answers to which I do not understand.  If possible, please point out my error.  Please, follow the links for print screens.

Thank you!!!

  In Test 1, there is a question about Strings.  
   
   
   
    The correct answer is F, which I understand.  However, the explanation goes on to say that if method call was equals instead of equal, the correct options would be A, C and E.  WHY E and not D???  I tried it out, and indeed, it prints "four" instead of "five".  What am I not seeing?

   

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also not able to understand this, please update if you get the answer.
 
author & internet detective
Posts: 39280
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Elana Abelev wrote:Hello!  This question is not about the books but about the test bank that is provided as a resource with the purchase of the book.  I wish that Sybex would provide question discussion forums for each question, similar to Enthuware setup.  


Well, the good news is us others read this forum often .

The reason it is D and not E has to do with the string pool.  D is true because s is assigned the string "Hello". This string is from the string pool. And option D is comparing to the literal "Hello" - the same one from the string pool.  In E, "Hello" is still from the thread pool. However, variable t is not. The String constructor is called making it a reference to a different object.

Does that make sense?
 
Elana Abelev
Ranch Hand
Posts: 30
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Elana Abelev wrote:Hello!  This question is not about the books but about the test bank that is provided as a resource with the purchase of the book.  I wish that Sybex would provide question discussion forums for each question, similar to Enthuware setup.  


Well, the good news is us others read this forum often .

The reason it is D and not E has to do with the string pool.  D is true because s is assigned the string "Hello". This string is from the string pool. And option D is comparing to the literal "Hello" - the same one from the string pool.  In E, "Hello" is still from the thread pool. However, variable t is not. The String constructor is called making it a reference to a different object.

Does that make sense?


Certainly glad others are reading this forum!  Picked up a lot of useful info here, thank you.

Your explanation makes sense (and that's what I think too), but the answer key in the test seems to disagree.  Check out my second link - it shows the official answer that pops up and it states that if method called were correct, option E (NOT D) would be the correct one.  Is there a mistake in the explanation of the question?
 
Jeanne Boyarsky
author & internet detective
Posts: 39280
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right! I went to add it to the errata and saw it was already logged and first reported here.
 
Elana Abelev
Ranch Hand
Posts: 30
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:You're right! I went to add it to the errata and saw it was already logged and first reported here.



Thank you.  I tried searching for this, but must have used wrong search keywords, because nothing came up.   Sorry for duplicate post!
 
Jeanne Boyarsky
author & internet detective
Posts: 39280
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries. It's hard to search for because Sybex randomizes the question numbers on the mock questions. It wasn't until I recreated my logic for logging the errata that I noticed it was already there!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!