File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does hashcode mean?

 
Mohit Jain
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers

What do we understand by an 'object hashcode'. What does an object hashcode represent and how is it calculated.

Please help me to understand this.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From http://en.wikipedia.org/wiki/Hashcode

A hash function is a reproducible method of turning some kind of data into a (relatively) small number that may serve as a digital "fingerprint" of the data. The algorithm "chops and mixes" (i.e., substitutes or transposes) the data to create such fingerprints. The fingerprints are called hash sums, hash values, hash codes or simply hashes. (Note that hashes can also mean the hash functions.) Hash sums are commonly used as indices into hash tables or hash files.


Using hash codes rather than unique values can substantially speed or simplify code.
 
P Ventura
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hashcode is used in collections. It's used to find a bucket where your object will be inserted. If you don't understand this, read something about Collections and Maps and all will be clear.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the API documentation for the method java.lang.Object.hashCode():
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

Collection classes such as Hashtable, HashMap and HashSet use hashcodes for efficiency.

The hashCode() method in a class has to adhere to specific rules, which are described in the API documentation for the hashCode() method in class Object. Note that if you write a class with an equals() method, you should also implement the hashCode() method according to the rules.
 
Stephen Zhang
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://mindprod.com/jgloss/hashtable.html
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep in mind that although hashcodes are sometimes considered "digital fingerprints" (as referenced in the Wikipedia article), they are not necessarily unique. Two unequal objects might have the same hashcode and still comply with the hashcode contract (described in the API under Object's hashCode method). On the other hand, equal objects should always return the same hashcode. It's important to understand this distinction for the exam.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic