I believe that every object I create, has its unique ID in JVM. I want to get that ... lets say print on the console.
Can anyone help me with this...
Ill be thankful
Printable View
I believe that every object I create, has its unique ID in JVM. I want to get that ... lets say print on the console.
Can anyone help me with this...
Ill be thankful
Each object has a unique hash value which you can treat as unique ID for that object.
Output:Code:String abc = new String("Australia");
System.out.println("Hash code for String object: " + abc.hashCode());
Student obj = new Student();
System.out.println("Hash code for Student object: " + obj.hashCode());
Code:Hash code for String object: -1357076128
Hash code for Student object: 26022015
Thanks mate. Works fine.
It is an interesting info for me.
It can be important in many cases. Important thing to remember is that hash codes are signed numbers(long). I miss that point in many cases when I'm learning it. Since that hashCode() can be overridden by subclasses you may associate with your own hash code with object.