The Java language itself is cross-platform, and if the technology for invoking DLLs through Java is easy to use, using Java to develop the foreground interface can be faster and more cross-platform.
When Java invokes a DLL library that is written by C + +, it is prone to problems in parameter passing because of different basic data types and possible differences in the use of byte sequences.
Scenarios that use Java to invoke DLL dynamic-link libraries usually have three kinds: JNI, Jawin, Jacob. where JNI (Java Native Interface) is a method of invoking a locally compiled library of functions provided by the Java language itself, it is cross-platform and can invoke different local libraries on different machines. Both Jawin and Jacob are sourceforge.net open source projects that are based on JNI technologies that rely on the implementation of Windows to make it easier to use COM and DLLs under Windows platforms.
Third, JNI
Sun Related documents: http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html
http://www.bt285.cn/or http://www.5a520.cn/.
Complete example of JNI: http://www.pconline.com.cn/pcedu/empolder/gj/java/0506/642328.html
The application scenarios for JNI are mapped based on Java classes and local functions. The steps to use DLLs are relatively cumbersome, involving not only Java programming, but also C/s programming.
The steps to use JNI are:
1. Write a Java class that uses this class to declare a function service that the DLL provides externally, where the Java method is declared as native, and its method signature can be customized without implementing the function body.
2. Use the Javah tool to generate the corresponding. h header file for this Java class.
3. The most important and troublesome step: to write the functions declared in the C/h header file, which contains the jni.h header file, and is programmed using the data type defined in the code as the input and return data type of the function. Data type conversions are implemented in this way. For example, the data type: Boolean (Java) Àjboolean (jni.h:typedef unsigned char jboolean), using the data type Jboolean in its own compiled/C code to map a Boolean type in Java. In this step, you can call a DLL library that already exists in C + + code.
4. You can use the Java class when you write another Java code.
In step 3rd, when you write the C/a function, you can use a env pointer called interface pointer to invoke a series of (many) functions provided by JNI, using these functions to access the objects and data of the JVM.
The disadvantage of using JNI is that it is cumbersome to use, and you need to encapsulate existing DLLs, and you need to know more about C + +.
Advantages of using JNI: You can invoke the local library across platforms.