Archives
Since the short 1 is represented as 00 00 00 01 on big endian machines and 01 00 00 00 on little endian machines, it’s a rather straight forward matter to detect the endianness of a machine, by simply looking at how it stores a short. #include <stdio.h> int main() { unsigned short i [...]
I recently wrote an article about calling C code from Java using JNI. Another way to call C code from Java is to use Java Native Access, which makes things significantly easier. First off, we’ll need to write the C library. Create a ctest.c file containing a simple helloFromC function: /* ctest.c */ #include [...]
In this tutorial we’ll be creating a Java application calling code from a native library. We’ll have a Java application called HelloWorld which will call the function helloFromC from a shared library named “ctest“, using Java Native Interface. First off, we’ll create a file named HelloWorld.java to contain the HelloWorld class. /* HelloWorld.java */ [...]