Using JNI technology, we can call each other between C/C ++ and Java.
1. Java calls the C/C ++ Interface
This is the most basic application of JNI. JNI has many sample codes for this purpose. C/C ++ is generally written as a dynamic link library. In the Java program loadlibrary, the call can be completed using the Native Interface.
Note: In Mac, the name of the dynamic link library is not necessarily libhello. So. It may be libhello. jnilib.
2. C/C ++ callback Java Interface
In this usage, there are few examples of JNI. In fact, it is relatively simple, and JNI also provides such an interface. For example, getobjectclass, getmethodid, callobjectmethod, newobject, findclass, and other interfaces can call C/C ++ on Java interfaces.
In addition, one thing to note is about signature. For example, in jmethodid getmethodid (jclass clazz, const char * Name,
The third parameter in the const char * sig function requires the signature of the function. How can we know the signature of the Java method?
In fact, JDK provides the signature for viewing Java methods. The method is as follows:
(1) cmd: Go to the directory where XXX. Class is located.
(2) enter the command javap-s xxx
(3) The results are displayed in front of you.
Extension: Android ndk is similar. It can also achieve interaction between C/C ++ and Java.