JNI is (Not) Your Friend

Introduction So far we’ve scratched the surface of using JNI when we looked at wrapping a C library and Calling Java from C. Now we’re going to look into some more complex uses. Java Class Since we’re working with JNI, we’ll need a Java class to use what we’re going to expose from C. DemoFuncs.java class DemoFuncs { static { System.loadLibrary("demo_lib"); } public enum Days { MON, TUE, WED, THU, FRI, SAT, SUN, } public static native int[] demo_array_return(); public static native int[] demo_array_copy_inc(int[] in); public static native Days demo_enum_val(); public static native Days demo_enum_field_val(); public static native void demo_exception_1(); public static native void demo_exception_2(); public static native void demo_exception_3(); public static native boolean demo_exception_4(); public static native Name demo_name(String name); } Note: This class includes an enum because one of the later examples uses them....

July 9, 2017 · John

Calling Java From C

Introduction Obviously, JNI lets you call Java functions and use Java classes in C. Typical a Java app is the one calling into C. Now Let’s say you don’t have a Java app that kicks off the process but you want your C app to still use some Java code. Okay, I know what you’re thinking, “why”? Well, there are companies out there that provide SDKs for their products only in Java....

June 17, 2017 · John

Wrapping a C library in Java

Introduction It can’t be argued that Java is popular and successful. It is consistently the number one language on TIOBE’s popularity list, above C which comes in as number two. This ranking is based on popularity and doesn’t mean Java is more used than C but that doesn’t change the fact that there is a lot of Java code out there. Unlike other languages interop with Java is not what I’d call easy....

June 6, 2017 · John