A: Using non-Java code

Bruce Eckel’s Thinking in Java Contents | Prev | Next

This
appendix was contributed by and used with the permission of Andrea Provaglio (
www.AndreaProvaglio.com).

The
Java language and its standard API are rich enough to write full-fledged
applications. But in some cases you must call non-Java
code; for example, if you want to access operating-system-specific features,
interface
with special
hardware
devices, reuse a pre-existing, non-Java code base, or implement
time-critical
sections of code. Interfacing with non-Java code requires dedicated support in
the compiler and in the Virtual Machine, and additional tools to map the Java
code to the non-Java code. (There’s also a simple approach: in Chapter
15, the section titled “a Web application” contains an example of
connecting to non-Java code using standard input and output.) Currently,
different vendors offer different solutions: Java 1.1 has the
Java
Native Interface (JNI), Netscape has proposed its
Java
Runtime Interface, and Microsoft offers
J/Direct,
Raw
Native Interface (RNI), and
Java/COM
integration.

This
fragmentation among different vendors implies serious drawbacks for the
programmer. If a Java application must call native methods, the programmer
might need to implement different versions of the native methods depending on
the platform the application will run on. The programmer might actually need
different versions of the Java code as well as different Java virtual machines.

More by Author

Must Read