Java
  Home arrow Java arrow Interacting With C From Java With JNI: Par...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Interacting With C From Java With JNI: Part 1/2
By: Neville Mehta
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2002-07-02

    Table of Contents:
  • Interacting With C From Java With JNI: Part 1/2
  • Java Native Methods
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


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


    (Page 1 of 3 )

    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.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.

    More Java Articles
    More By Neville Mehta


       · Heh heh, Anonymous Loozah, Seems Like no one found this very helpful, (posted almost...
     

    JAVA ARTICLES

    - 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 ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek