Chapter 9. Understanding JNI

Apple ships Java on every Mac. Java is an important part of OS X. Many applications for OS X are Java-based. Apple has a very strong commitment to providing a stable OS X-integrated Java experience to its users.

However, Java is just a small part of OS X. I describe in earlier chapters the Cocoa frameworks, Carbon frameworks, and Unix libraries. Many of these libraries are written for C or C-based languages.

Thankfully, Java is not a C-based language. Normally, you don't have to worry about pointers, cleaning up memory, allocating memory, and a host of other nasty little details that C-based languages deal with all the time.

Still, access to Cocoa, Carbon, and POSIX libraries is useful sometimes. The standard approach on OS X to access Cocoa, Carbon, and Unix libraries from Java is Java Native Interfaces (JNI). JNI provides access to all Cocoa frameworks, Carbon frameworks, and POSIX libraries from Java.

JNI tends to frighten beginning and advanced Java programmers. Visions of pointers to pointers and function callbacks passed around with esoteric #define statements cause dread, and even hardened Java programmers cringe when the acronym "JNI" is spoken.

Remember, the famous words of Douglas Adams. "DON'T PANIC. JNI really isn't any more difficult than creating Java GUI layouts by hand. JNI just takes practice." (OK, ...

Get Java® and Mac OS® X now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.