John Chamberlain
JavaOne 2002 Technical Session #2253: An Introduction to the Java Native Interface (JNI)
Friday, March 29, 2002, 1:30pm - 2:30pm, Room 102, Moscone Center, San Francisco
 Abstract
This session covers the essentials of the JavaTM Native Interface (JNI). The key role the native interface plays as the glue between the Java class libraries and the run-time platform is described. The session then shows how to use JNI to improve code performance and access platform-specific features. Competing advantages and disadvantages of using JNI are detailed. The session also covers how to programmatically start the Java virtual machine or embed it in a native application.
You benefit by gaining a deeper understanding of how the Java class libraries work and learning how to exploit JNI for greater performance and flexibility. You also learn how to launch the Java virtual machine from your own code or custom startup program and how to embed the virtual machine inside an application that uses it. By the end of the session, you will know the advantages and disadvantages of JNI and be able to make intelligent decisions about when it is appropriate to use it.  
 Outline
Caveat: This is an approximate outline only. The exact topics covered in the session may vary.
Intro: What is the native interface and what can it do?

How the Java Foundation Classes Use JNI
      All native calls in Java 2 are standardized to use JNI
      How the Java classes call a native method
      How native code accesses and manipulates Java objects
      Example: how a Swing component creates its native peer

Using JNI to Improve Code Performance and Access Platform-Specific Features
      The cost of calling a native method: when does it make sense to do so?
      Typical uses of JNI on standard platforms
      Uses of JNI on special platforms such as embedded and hand-held devices
      Example: using JNI to do a DirectX multimedia animation from Java

Advantages and Disadvantages of JNI
      Advantages: faster code
      Disadvantage: less portability
      Advantage: ability to use otherwise inaccessible platform features
      Disadvantage: native code is painstaking to write and harder to debug

Controlling the Java Virtual Machine
      How to programmatically start the Java virtual machine
      How to embed the Java virtual machine in a native application

Conclusion: Knowing the capabilities and limitations of JNI enables you to take maximum advantage of it
 Examples and Source Code
The resources for the "Java Bunny" custom launcher demo are posted below. More will be made available when I get back in the second week in April.
Java Bunny launcher example 

JavaOne Tech Session #2253 - An Introduction to JNI · speaker@johnchamberlain.com · Revised 1 February 2002