aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About Object" Watch "About Object" New topic
Author

About Object

Wahid Sadik
Ranch Hand

Joined: Oct 30, 2000
Posts: 56
According to Mughal, following 2 statements are wrong. Can anyone explain?
1. If the references 'x' and 'y' denote two different objects, then the expression 'x.equals(y)' is always false.
I think: In some classes 'equals()' is overridden and forced to behave differently as in 'Object' class.
One example is 'String' class, which will check for same sequence of characters, if used as above.
The term 'always' is reason why the statement is wrong.
2. If the references 'x' and 'y' denote two different objects, then the expression 'x.hashcode()==y.hashcode()' is always false.
I think: I've read different things about 'hashcode()' or I've misunderstood it.
According to Mughal, 'hashcode()' will generate a unique hash value for an object.
According to JDK 1.3 documentation, if 'x.equals(y)' evaluates to 'true', then their hash values will be same.
Again, the term 'always' is reason why the statement is wrong.
Still, I need elaborate explanation about hashcode. Any help?

Regards<br />Mohammod Wahid Sadik<br />SCJP 1.2, SCJD 1.4,<br />IBM Certified XML Developer<br />IBM Certified UML Designer
Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
For the question 1) I share the same view as you do.
For question 2)PLease note that if 2 objects are unequal (i.e. obj1.equals(obj2) is false) then, there is no requirement that the hashcodes produced by the 2 objects be the same.
However, producing distinct hascode values for different objects may improve the perfomance of hastbales. This is what the api says.
Hope this helps.

- Sathvathsan Sampath
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Object