the generic object class defined in java comes with default hashcode(method for mapping each object instance to an integer that is "representationof that ob ject specificallythe hashcode(method returns -bit integer of type int un less specifically overriddenthis method is inherited by every object used in java program we should be careful in using the default object version of hashcode()howeveras this could just be an integer interpretation of the object' location in memory (as is the case in many java implementationsthis type of hash code works poorly with character stringsfor examplebecause two different string ob jects in memory might actually be equalin which case we would like them to have the same hash code indeedthe java string class overrides the hashcode method of the object class to be something more appropriate for character strings like wiseif we intend to use certain objects as keys in mapthen we should override the built-in hashcode(method for these objectsreplacing it with mapping that assigns well-spreadconsistent integers to these types of objects let us considerthenseveral common data types and some example methods for assigning hash codes to objects of these types casting to an integer to beginwe note thatfor any data type that is represented using at most as many bits as our integer hash codeswe can simply take as hash code for an integer interpretation of its bits thusfor java base types byteshortintand charwe can achieve good hash code simply by casting this type to int likewisefor variable of base type floatwe can convert to an integer using call to float floattointbits( )and then use this integer as ' hash code summing components for base typessuch as long and doublewhose bit representation is double that of hash codethe above scheme is not immediately applicable stillone possible hash codeand indeed one that is used by many java implementationsis to simply cast (longinteger representation of the type down to an integer the size of hash code this hash codeof courseignores half of the information present in the original valueand if many of the keys in our map only differ in these bitsthen they will collide using this simple hash code an alternative hash codethenwhich takes all the original bits into considerationis to sum an integer representation of the high-order bits with an integer representation of the loworder bits such hash code can be written in java as follows