This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes hexadecimal representation of hash code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hexadecimal representation of hash code" Watch "hexadecimal representation of hash code" New topic
Author

hexadecimal representation of hash code

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Hi All,
when print the object , why it shows the hexadecimal representation of hash code followed by classnamse@ ?How java internally do this ?

Thanks,
Satya
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Why? Because that's what the writers of the JVM decided to do.

How does the JVM do it? It's just programming. Why do you need to know that?
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 430
    
    1

Hi,

simply I think standard toString() method is called.

I think that returning className+@+HEX of the hash code was an implementation choice since Java 1.0, a way to return a string without a meaning but at least with a semantic....

You can look at official Java documentation, there's explained how default toString() works.
Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 186
S Majumder wrote:when print the object , why it shows the hexadecimal representation of hash code followed by classnamse@ ?

As Paul has said, Because that's what the writers of the JVM decided to do.

S Majumder wrote:How java internally do this ?


For more information:
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()
S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Thanks Paul and Claude for the reply
I know if we override the toString() as per our requirement ....
But I need to know how its actually work behind the back , when the method is not overridden , you can say its just my curiosity ..

regards,
Satya
S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Gaurangkumar Thanks a lot ,,, for the link .


-Satya
Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 186
S Majumder wrote:Gaurangkumar Thanks a lot ,,, for the link .

You are welcome
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

S Majumder wrote:But I need to know how its actually work behind the back , when the method is not overridden , you can say its just my curiosity ..


Well, it looks like Gaurangkumar Khalasi has explained that. As for your curiosity, that's all very well, but if you also have the goal of being a Java programmer, then in my opinion you're wasting your time with all of these questions you are posting here.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

If you want to see how a method such as Object.toString() is implement, then you can lookup the source code - you can find it in the file src.zip which is in your JDK installation directory.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
wood burning stoves
 
subject: hexadecimal representation of hash code
 
Similar Threads
From sun java class documents
this.xxx
crack the output!
Vector reference?
Print Object output incorrect - Head First Java Chapter 16 TreeSet Exercise