publicclassCraftJNI {static {System.loadLibrary("hello"); // Load native library hello.dll (windows)// or libhello.so (Unixes) at runtime.// This library contains a native method sayHello() }// Declare an instance native method sayHello() which receives no parameter// returns voidprivatenativevoidsayHello();// Test Driverpublicstaticvoidmain(String[] args) {newCraftJNI().sayHello(); // Create an instance and invoke native method }}
#include<jni.h>// Standard JDK provided header#include<stdio.h>// Standard C IO header#include<CraftJNI.h>// Generated headerJNIEXPORT void JNICALL Java_CraftJNI_sayHello(JNIEnv *env, jobject thisObj) {printf("I am in C code \n");return;}