Search code examples
javajava-native-interfacefortranjna

JNI vs JNA, calling Java from Fortran95


I am trying to implement the following: Compute something in Java and return value to Fortran. I implemented it using JNI and the sequence is as follows:

Fortran 95 -> C -> Java (Computes something)

 Java (returns value to Fortran 95) -> C -> Fortran95

Can this be achieved using JNA? If so, what are the advantages?


Solution

  • Fortan's shared libraries are compatible with C, so JNA should be able to access any interfaces exported, including those that have callback inputs.

    The advantages of JNA over JNI:

    • Speed of development You don't have to configure or compile any native code, which can significantly speed up your development/build cycle.
    • Clarity JNA's mappings look just like the functions you'd be calling in native code, but you get to use Java semantics instead of translating Java into C/JNI, and then C/JNI into appropriate wrappers around Fortran
    • Maturity of Code JNA has already worked out the gotchas and details of managing the native interface, so you can focus on solving your real problems instead of doing plumbing. However, if you like to do plumbing, JNI is always there.