aspose file tools*
The moose likes Beginning Java and the fly likes hash codes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hash codes" Watch "hash codes" New topic
Author

hash codes

chathura jayaweera
Greenhorn

Joined: Nov 14, 2004
Posts: 1
I want to know more details about hash codes.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
When you create instance of any class ( object of any class ) , it live on GCH . So there are lots of object at any time live on GCH So to identify them uniquely JVM gives them a unique key that is known as Hash Code .

I know you want details but hope this may help .
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by rathi ji:
...there are lots of object at any time live on GCH So to identify them uniquely JVM gives them a unique key that is known as Hash Code.

No, hashCode is not a unique key. Per the hashCode contract, equal objects (as defined by the equals method) should return the same hashCode, but there is no requirement that unequal objects return different hashCodes.

See the "hashCode" and "equals" methods in the Java API for Object...

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html

Essentially, hashCode provides a means of "classifying" objects so that they can be "arranged" for faster retrival from a Container like HashSet. For detailed information, see the section, "Hashing and hash codes" in Chapter 11 of Bruce Eckel's Thinking in Java...

http://www.faqs.org/docs/think_java/TIJ313.htm (scroll down about 2/3)
[ January 13, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
rathi, I suggest you take a beginner's course in Java from Sun. SL-110 followed by SL-275 will serve you well.
There you'll learn just about everything you're asking questions about and now misinforming people about.


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hash codes
 
Similar Threads
HashMap and HashTable
hashCode question
K&B doubt in hashcode() and equals(): Is my understanding correct ?
Shift operators
class Object. Method equals().