Skip to main content

Posts

Showing posts from May, 2010

JNI Simple Tutorial

After a long break I am posting a simple tutorial on JNI which is one of my favourites. JNI is Java Native Interface, which we can use to call the native methods written in languages other than Java. We are going to call a method written in C++. JNI is very useful where you cannot use Java such as getting system hardware information and much more, it depends up on what you need. For this tutorial you need to read my old post on creating a simple dll in VC++, though if you know how to create DLL's using VC++ then you can skip that post. Lets get started with our tutorial.. First step is to write a class which will use JNI. Well its too simple, following is the code for our Java class which will be using JNI import java.io.*; class JNITest { // native method public native static void WinMessage(String str); static { System.loadLibrary("SimpleDll"); } public static void main(String args[]) { WinMessage("Hello From JNI"); } } After writing this J