Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

equals() method and == operator

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Head first EJB book page 292 question 6: According to basic Java rules if two objects are equals(), they are similar, identical but may not be the same. If two objects are == then they are same. Am I correct? Then the answer for this question should be A. Am I missing something? Please help! Thank you very much.
[ March 07, 2004: Message edited by: Nesan Krish ]
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If object1 == object2 returns true, they reference to the same object. But if object1 == object2 returns false, the objects may still refer to the same entity (i.e. the primary key objects contain the same data which implies that equals-method returns true).
Thus, only B is correct.
 
Nesan Krish
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this mean that two seperate primary keys can point one entity?
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nesan,

Does this mean that two seperate primary keys can point one entity?

No. It means there are two objects holding same PK hence pointing to the same entity.
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, can you post the question if its not big? I dont have the book.
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic