Programmming in C/C++ with the Java Native Interface

Matthew Mead


API Application Program(ming) Interface

The interface (calling conventions) by which an application program accesses operating system and other services. An API is defined at source code level and provides a level of abstraction between the application and the kernel (or other privileged utilities) to ensure the portability of the code.

An API can also provide an interface between a high level language and lower level utilities and services which were written without consideration for the calling conventions supported by compiled languages. In this case, the API's main task may be the translation of parameter lists from one format to another and the interpretation of call-by-value and call-by-reference arguments in one or both directions.

DLL Dynamically Linked Library

A library which is linked to application programs when they are loaded or run rather than as the final phase of compilation. This means that the same block of library code can be shared between several tasks rather than each task containing copies of the routines it uses. The executable is compiled with a library of "stubs" which allow link errors to be detected at compile-time. Then, at run-time, either the system loader or the task's entry code must arrange for library calls to be patched with the addresses of the real shared library routines, possibly via a jump table.

The alternative is to make library calls part of the operating system kernel and enter them via some kind of trap instruction. This is generally less efficient than an ordinary subroutine call. It is important to ensure that the version of a dynamically linked library is compatible with what the executable expects.

Examples of operating systems using dynamic linking are SunOS, Microsoft Windows and RISC OS on the Acorn Archimedes.

GC Garbage collection

The process by which dynamically allocated storage is reclaimed during the execution of a program. The term usually refers to automatic periodic storage reclamation by the garbage collector (part of the run-time system), as opposed to explicit code to free specific blocks of memory.

JVM Java Virtual Machine

A specification for software which interprets Java programs which have been compiled into byte codes. The JVM instruction set is stack-oriented, with variable instruction length. Unlike some other instruction sets, the JVM's supports object-oriented programming directly by including instructions for object method invocation (similar to subroutine call in other instruction sets).

The JVM itself is written in C and so can be ported to run on most platforms. It needs thread support and I/O (for dynamic class loading). The Java byte code is independent of the platform.

There are also some hardware implementations of the JVM.

JNI Java Native Interface

A native programming interface for Java that allows Java code running inside a Java Virtual Machine to interoperate with applications and libraries written in other programming languages such as C, C++ and assembly language.

Shared library

See DLL

Definitions from Sun's JNI FAQ (not much as of this writing)
http://wagner.Princeton.EDU/foldoc http://java.sun.com/products/jdk/faq/jnifaq.html

Copyright © 1998 Sergio Antoy. All Rights Reserved
February 99, version 020199