1

I was checking Object class in java and found that hashCode, notify, wait and few other methods are native methods.

public final native void wait(long timeout) throws InterruptedException;

Are these methods not implemented using java language? Some other programming language (i guess C) is used to implement these methods?

Kindly help me in getting clear picture here.

Thanks, Gaurav

GAURAV PANT
  • 135
  • 4
  • 11
  • http://stackoverflow.com/questions/18900736/what-are-native-methods-in-java-and-where-should-they-be-used http://stackoverflow.com/questions/6101311/what-is-the-native-keyword-in-java-for – Alex Chermenin Sep 29 '16 at 11:24
  • Hey Alex, I want to know specifically about these methods of Object class. Concept wise I know why native keyword is used in Java. – GAURAV PANT Sep 29 '16 at 11:26
  • This native methods implemented in JVM code via C++. – Alex Chermenin Sep 29 '16 at 11:27
  • Possible duplicate of [Why are hashCode() and getClass() native methods?](http://stackoverflow.com/questions/10578764/why-are-hashcode-and-getclass-native-methods) – Frederic Klein Sep 29 '16 at 11:43
  • Your question is underspecified because each JVM implementation can do it differently. In the case of HotSpot it's C++. – Marko Topolnik Sep 29 '16 at 12:07

1 Answers1

1

They have to use C as the hashCode() works on the Objects header.

notify/wait uses system calls which are not available any other way.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130