2

I would like to know if it is possible to get the Native Code implementation of JDK methods, such as:

public final class System {

/* First thing---register the natives */
private static native void registerNatives();
...
....}
coolguyxp
  • 31
  • 5
Prateek
  • 12,014
  • 12
  • 60
  • 81
  • possible duplicate of [Where to find source code for java.lang native methods?](http://stackoverflow.com/questions/2292629/where-to-find-source-code-for-java-lang-native-methods) – durron597 Dec 11 '12 at 00:21

3 Answers3

2

Search for OpenJDK source code (it is open source), or any other open-source Java implementation and you can find the implementations.

The System class source for example (grabbing the complete OpenJDK source might be more convenient than this 'web view').

Note: registerNatives() is using native (C/C++ ?) code, so you'd need to track that down (from the complete source code for example). Or any other implementation you are interested in.

Veger
  • 37,240
  • 11
  • 105
  • 116
  • The question is **about** native code, so no wonder it seems to be using it :) – Marko Topolnik Dec 10 '12 at 13:03
  • True :) But my answer is more in the line of 'choose your favorite open-source Java implementation and check out the code, with an OpenJDK example'. More like a pointer than the exact answer, so it is more generic applicable. – Veger Dec 10 '12 at 13:10
  • Except it misses the crucial link to the actual piece of code. Java source code is trivially easy to look up. – Marko Topolnik Dec 10 '12 at 13:11
1

Above part of code is not enough to implement native method, you can find detailed information http://www.javaworld.com/javatips/jw-javatip23.html

umert
  • 138
  • 1
  • 6
1

All this is available from the OpenJDK Mercurial repo web view, but it is far from trivial to track down.

This here is a link to java.lang.System native code in the newest development version of JDK 7 Update stream. Hopefully you'll find your way around from there.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436