• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object class source in openJDK

 
Greenhorn
Posts: 24
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

I usually study java source to learn how it work at backend. But when I saw the Oject class I only found the method declaration and no definitions. Can anyone tell the reason or can provide the source for Oject class containing all methosddefinitions.


Thanks in advance.

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to add sources jar along with your binary jar into IDE for viewing the source code if not added by default.
 
Ganesh Gore
Greenhorn
Posts: 24
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mahesh Kedari wrote:You need to add sources jar along with your binary jar into IDE for viewing the source code if not added by default.




I know that, I have the Oject.java file but there are method definitons inside. Then where are the common methods like Equal and Hashcode are defined. Because only their declaration is present as seen in source file. Please check and let me know.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look at the source code of class Object, you'll see that some methods are native:

That means those methods are not implemented in Java, but in another language (probably C or C++).

If you really want to see the source code, you'd have to download the complete source code of OpenJDK. It's a very big project that is probably not easy to understand.
 
Ganesh Gore
Greenhorn
Posts: 24
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jesper, this is the reply I was expecting .
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Gore wrote:Then where are the common methods like Equal and Hashcode are defined. Because only their declaration is present as seen in source file.


Where did you get the source file from ? The one in the src.zip in the JDK contains an implementation for equals().
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stuart A. Burkett wrote:

Ganesh Gore wrote:Then where are the common methods like Equal and Hashcode are defined. Because only their declaration is present as seen in source file.


Where did you get the source file from ? The one in the src.zip in the JDK contains an implementation for equals().


That is because, as Jesper de Jong has already pointed, native methods do not have code in Java file, and equals method is not a native method (other such methods are toString, finalize etc.).

I hope this helps.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anayonkar Shivalkar wrote:

Stuart A. Burkett wrote:

Ganesh Gore wrote:Then where are the common methods like Equal and Hashcode are defined. Because only their declaration is present as seen in source file.


Where did you get the source file from ? The one in the src.zip in the JDK contains an implementation for equals().


That is because, as Jesper de Jong has already pointed, native methods do not have code in Java file, and equals method is not a native method (other such methods are toString, finalize etc.).

I hope this helps.


I know that. If you read the part of Ganesh's post that I quoted, he was saying that the source code he had did not have an implementation for the equals method. I was asking him where he got that source code from because the source code in src.zip in the JDK does have an implementation of the equals method.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Gore wrote:Then where are the common methods like Equal and Hashcode are defined.


Did you specifically look for those methods? Because in Oracle's JDK, equals method is not native, but hashCode method is native.
 
Ganesh Gore
Greenhorn
Posts: 24
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anayonkar Shivalkar wrote:

Ganesh Gore wrote:Then where are the common methods like Equal and Hashcode are defined.


Did you specifically look for those methods? Because in Oracle's JDK, equals method is not native, but hashCode method is native.




Yes I wanted to see how hashcode is generated in hashcode method of Object class.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Gore wrote:Yes I wanted to see how hashcode is generated in hashcode method of Object class.


Well, as I've mentioned, the method is native, so its quite tricky to see the actual underlying code - which might be in C, C++ and/or assembly.
reply
    Bookmark Topic Watch Topic
  • New Topic