my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan Chisholm's Topic Exam Q.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Chisholm Watch "Dan Chisholm New topic
Author

Dan Chisholm's Topic Exam Q.5

Maria Garcia
Ranch Hand

Joined: Jul 14, 2002
Posts: 86

The answer is 1026. How did you come up with this answer Dan ?


SCJP 1.4
Maria Garcia
Ranch Hand

Joined: Jul 14, 2002
Posts: 86
oops!! i made a boo-boo... I got it now.
Ray Chang
Greenhorn

Joined: Sep 10, 2002
Posts: 25
Can you explain? thank you.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by Ray Chang:
Can you explain? thank you.

If you would like to know how the hash code is calculated then just move the print statement into the hashCode method.


A good hashcode calculation for an array will use the value of each element of the array. An even better hashcode method for an array will also depend on the position of each value in the array. The following is an example of a hashcode method that does not produce unique hashcodes for arrays that contain the same set of elements in different orders.

The result is "6,6,6". A better hashCode method produces unique values when the position of the array elements is changed.

The result is "1026,2016,2946".


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

Joined: Aug 05, 2002
Posts: 787
Hi Dan:
I am trying to find an easy read on HashCode() method. Can you suggest one?
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Take a look at item 8 of Chapter 3 of Effective Java.
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Thanks Dan...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan Chisholm's Topic Exam Q.5
 
Similar Threads
Dan Mock Exam Question(Hascode)
Hashcode
a hashCode question
hash code doubt from dan's ques
Immutable - Hashcode() - lazy initialization.