Native methods are functions written in C or C++, compiled into a library,
and dynamically loaded by the Java runtime. This article describes how Java
programs can call native methods, and how native C code can create Java
objects and invoke Java methods. The examples are written for Windows 95,
Windows NT and Solaris, and should be portable to other platforms.
Benefits and Limitations of Native Methods
We begin with a short discussion of the pros and cons of using native
methods. Using native methods adds complexity and effort to a development
project, so you would usually only use them if you had to.
Why Use Native Methods?
Some of the most common reasons for using native methods are:
You need to do something Java can't do, such as accessing a system library
that has a C API.
You want to re-use an existing body of code implemented in another language.
You need the perfo... (more)