I hope this will work for you.
There are some native methods in the Object class, because it has to interact with the machine. Here machine dependent code is written in the C language, which is not coming with the source package or in rt.jar
of the lib location of the Java Runtime Environment (JRE).
One more reason for being native is possibly for the performance reasons. Due to the C level programming performance may be improved, hence they may have written the native code in the C language.
The methods are native because they concern native data.
You can find the complete source code of the native methods here.
Coming to your second question:-
Normally, in order for the JVM to find your native functions, they have to be named a certain way. e.g., for java.lang.Object.registerNatives
, the corresponding C function is named Java_java_lang_Object_registerNatives
. By using registerNatives
(or rather, the JNI function RegisterNatives
), you can name your C functions whatever you want.