Java Native Interface Idioms for C++ Class Hierarchies

01 December 2000

New Image

The Java(TM) Native Interface (JNI) provides a set of mechanisms for implementing Java methods in C or C++. JNI is useful for reusing C and C++ code repositories within Java frameworks. JNI is also useful for real-time systems, where complied C/C++ code executes performance-critical tasks, while Java code executes system control and feature tasks. Available JNI literature concentrates on creating Java proxy classes that allow Java clients to interact with C++ classes. Current JNI literature does not discuss Java proxies for entire C++ inheritance hierarchies; that is the topic of this paper. Our experience in reusing C++ class hierarchies within a Java framework has uncovered eight useful idioms for constructing Java proxy class hierarchies that mirror their C++ counterparts. The first section introduces JNI. The second section shows an example C++ class hierarchy. The third section examines the Java proxy class hierarchy for that C++ hierarchy in detail. The five idioms of this section support single inheritance method call semantics common to Java and C++, as well as method call semantics specific to C++. A fourth section on C++ multiple inheritance presents three idioms for multiple inheritance proxy classes and interfaces. A final section gives conclusions.