Java code for reading and writing from a serial port on a linux machine with JNI

To compile and link a java program whatever.java with a C program something.c:
  1. Compile the java program (produce a .class file)
     javac whatever.java 
  2. Generate a header file whatever.h for the C program to use
     javah whatever 
  3. Compile the C program to produce a shared library file (generate lib*.so that can be loaded at run time)
     gcc -shared -o libsomething.so something.c 
  4. Run the java program
     Java -Djava.library.path=$HOME/. whatever