aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's: Collection exam - tight language Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic
Author

Dan's: Collection exam - tight language

Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
Just a note Dan - and others -
In one of the questions:
As long as the fields used for the equals comparison remain unchanged the hashCode method must consistently return the same integer value.
To be specific and comply with API specifications of the contracts of the hashCode() method, it should be written:
In a class that properly override equals() and hashCode() methods, as long as the fields used by the equals() method for comparison remain unchanged, the hashCode() method must consistently return the same integer value during the same execution of a Java application.


Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Yes, I agree. There should definitely be a comma somewhere in there Dan.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
Barry, in the API, hashCode() contract does say - as you no doubt know -:

Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.

plus I can implement any hashCode() that doesn't comply with the contract, it is not properly implemented but it's legal.
Since Dan's exams are not mock exams but practice exams that aims to provide information, it is helpful to point out these information...
not about the commas...
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Alfred, I'm "pulling your leg"...
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
You managed to
Wonder why?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Seriously Alfred, we cannot expect Dan to give explanations as detailed as those available in the JLS. He, like you and I, is also learning Java and in a fantastically interesting way. I applaud his dedication and generosity in sharing his journey with us by producing this excellent learning material. Take the answers and explanations as pointers to JLS, and not as a detailed language specification.
-Barry
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
my attepmt was just because I apprciate his efforts and his good practice exams, I have to say, it was the resource that got my feet on rigid ground - with respect to Q n' A - after reading Mughal's. and I recommend it to everyone here. I was not complaining or criticizing, and I DO expect Dan to give very good explanation and provide very detailed information, cause this is what I have been experiencing while reading his exams...
Was just an attempt to make things clear... sorry that it was misinterpreted
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You have not done anything you need to apologise for Alfred.
-Barry
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Alfred,
I just uploaded the following update.

Suppose that class C has legal implementations of the hashCode and equals methods. Within any one execution of the Java application the hashCode contract requires that each invocation of the hashCode method of class C must consistently return the same result as long as the fields used for the equals comparison remain unchanged.
a. false
b. true

I think this new version is much better than the older version. Thank you for your input.
[ November 02, 2002: Message edited by: Dan Chisholm ]

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
You're welcome Dan, this is the quality I expect from you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's: Collection exam - tight language