Help on HashCode

1. I came to know that for every object created there will be an hashcode assigned. is that anything concerned with
memory address?

Yeah, a hashcode is assigned for every object created.  Identity and value of an Object are 2 important properties among others. Value may be the contents/state of the Object, Identity is that property of the Object using which you can distinguish
it from every other Object. Hashcode of an Object does serve as Identity most of the times. And yes the algorithm used by the Object class to get the hascode is said to be based on the memory address of the Object.

Hashcode is used to find objects in data structures such as Hashtable etc(There are also other identity based uses for it). The designers of the language anticipated that collections like Hashtable will be used a lot by programmers and provided a easy way to compute hashcode.

There's lot more to it, try google'ing on hashcode() and equals().
 

2, Also when ever im printing an object of a class itz string representation is like this classname@23e45g
My question is ,what that number signifies?

When you pass an Object to System.out.println what it prints is the return value of the toString method of that object. The above string representation which you have pasted is the default implementation of the toString() method in the Object class.

What you see is simple, its nothing but a concatenation of three things:
1)the name of the class
2) @
3)hascode() of the object in Hexadecimal

The name of the class can be obtained by using the getName() method on the Object's Class object. You can obtain the class object for any object by invoking the getCLass() method.

The implementation is simple:

public String toString() {
 return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }

Vinay.

Related:

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.