This project gives you some examples of using the JNI (Java Native Interface)
To build an example, run:
./gradlew build -p 00-helloworldThen, run it with:
./gradlew run -p 00-helloworld| # | Example | Aims |
|---|---|---|
| 1 | 00-helloworld | Using JNIEXPORT and JNICALL macros to declare native methods |
| 2 | 01-fibonacci | Using env->RegisterNatives() instead of JNIEXPORT & JNICALL macros |
| 3 | 02-echo | Work with many native types: jint, jshort, jlong, jfloat, jdouble, jstring, jboolean, jobject,... |
| 4 | 03-factory | Work with jmethodID and jfieldID, create a Java object in native code and return back to JVM |
| 5 | 04-exceptions | Handle an exception thrown by JVM and throw a new exception to JVM |
| 6 | 05-work | Demonstrate using thread in native code (*) |
(*) It's not recommended to spawn thread in native code, using Java Thread whenever it's possible.