Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2007, 01:07 PM
Member
 
Join Date: Nov 2007
Posts: 97
javaplus is on a distinguished road
Object ID
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-26-2007, 11:53 AM
Member
 
Join Date: Nov 2007
Posts: 12
javagk is on a distinguished road
Each object has a unique hash value which you can treat as unique ID for that object.
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());
Output:
Code:
Hash code for String object: -1357076128 Hash code for Student object: 26022015
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-26-2007, 11:58 AM
Member
 
Join Date: Nov 2007
Posts: 97
javaplus is on a distinguished road
Thanks mate. Works fine.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-26-2007, 12:19 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
It is an interesting info for me.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-26-2007, 01:08 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP - Application object example Java Tip Java Tips 0 03-17-2008 08:40 AM
Object sireesha New To Java 1 01-10-2008 02:31 AM
Object size kavithas New To Java 0 11-30-2007 01:00 PM
Creating object of Type Object class venkatv New To Java 3 07-17-2007 04:33 PM
Operator < cannot be applied to java.lang.Object, Object Albert Advanced Java 1 07-13-2007 04:19 PM


All times are GMT +3. The time now is 02:20 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org