Home arrow Java arrow Interacting With C From Java With JNI: Part 1/2
JAVA

Interacting With C From Java With JNI: Part 1/2


JNI allows us to write some code in C/C++ and then talk to that code through Java. In part one of this two part article, Neville introduces us to the concepts behind JNI with a simple example in C.

Author Info:
By: Neville Mehta
Rating: 4 stars4 stars4 stars4 stars4 stars / 24
July 02, 2002
TABLE OF CONTENTS:
  1. · Interacting With C From Java With JNI: Part 1/2
  2. · Java Native Methods
  3. · Conclusion

print this article
SEARCH DEVARTICLES

Interacting With C From Java With JNI: Part 1/2
(Page 1 of 3 )

Platform independence is one of the most common buzzwords in the industry today. Everybody wants flexibility. Everybody wants to program in his or her favorite programming language. Sometimes of course it's not a matter of choice, as some components of an application have to be programmed in a completely different language for whatsoever reason. Well, in Java we have JNI as a solution. Let me tell you in short what we can do using the JNI. Basically we can write code in other native programming languages (like C and C++) and use that same code in our java file.

JNI has a concept called native methods. We would have to declare all of the methods (which we would be coding) in other programming language as native. So let's get this concept straight once more before we proceed: JNI is the interface between the native programming language and the Java file (its like saying it's the technology that makes this whole thing work) and native methods are those methods which we will be coding in their native programming language (such as C or C++). The JNI and native methods collectively help us attain the flexibility in coding which we are looking for.

Again, like most of my articles, this includes practical examples so hopefully if all goes well, you would have a working example of Java interacting with C using the JNI.

Of course before you read on I will assume that you know the basics of C and Java. You will also need Java and C compilers, which are readily available. We will be using two C header files called jni.h and jni_md.h, which are present in the C:\jdk\include and C:\jdk\include\win32 folders respectively. Just copy and paste them in your current working folder for the time being so that we can include them in our C code.
blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials