Home » Programming » JAVA Tutorial

Using The Java Native Interface Topic:  JAVA Tutorial
Download (153) times
Last Download at Monday 06th of February 2012 06:42:41 PM

Using The Java Native Interface

In this tutorial we illustrate how the Java Native Interface (JNI) can be used to permit Java programs to communicate with C programs. We begin by compiling the Java program and the C program at the command prompt (i.e. outside of Eclipse) using the MinGW gcc compiler. Once the programs are compiled and executing correctly, we show how the programs can be integrated into an Eclipse project using the CDT plugin.

Whatever the reason for using it, the JNI bridges the gap between Java and C. It does this by accessing shared libraries that can be written in C (or possibly C++). We first write our Java code, identifying certain methods as belong to such a library. Then we write our C code and compile it into a library. We can then run our Java code as usual, and it will transparently access the library and run the native function.

The remainder of the code resembles standard Java code. An instance of the Hello class is created, and one of its methods, sayHello() is called. The fact that the method is native is irrelevant to the caller. Simply compile Hello.java as you would for any other Java source file (using javac Hello.java). The result will be a file called Hello.class.
Source: www.cs.umanitoba.ca

Download File Read PDF Online

Comments for Using The Java Native Interface


Related PDF Files

Eclipse Java IDE - Tutorial

Eclipse Java IDE - Tutorial This article describes the usage of Eclipse as a Java IDE. It

Introduction to Java threads

This tutorial is for Java programmers who have a good working knowledge of the Java. langu

Tutorial for Spring DAO with JDBC

This tutorial demonstrates how to work with data access objects in the spring framework. I

Java RMI Tutorial

Shows you the steps to follow to create a distributed version of the classic Hello World p

Generics in the Java Programming Language

You maybe familiar with similar constructs from other languages, most notably C++templates

Incoming Search: