wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes what is JNI and what are the advantages of JNI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "what is JNI and what are the advantages of JNI?" Watch "what is JNI and what are the advantages of JNI?" New topic
Author

what is JNI and what are the advantages of JNI?

Bilal Ali
Ranch Hand

Joined: Jun 14, 2007
Posts: 66
Respected Members,
I have heared a lot about JNI but never pratically worked on it, what I have concluded after discusisons with different people about JNI is that it is used to call the code and functions from other languages like C,C++,VB etc, now I need to ask that is this the only use of JNI I mean only used for calling functions from other languages or does it have some other features also,what are the conditions in which JNI comes handy or what are the conditions in which we can use JNI, also please post some tutorial from which I can leran JNI within few days, I am programming in J2SE,J2EE and J2ME from more than 3 years so what do you think that how long will I take to learn JNI.My last question is that in order to monitor the events in the operating system, including what key presses are occurring in other programs are doing, will I need to look at JNI, can i do this kinf od work purely in Java using JNI API or I have to write some code in C or VB and than call it from JNI.

Please reply as all of you have guided me in past.

Thanking You,
Bilal Ali.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Yes, JNI, the Java Native Interface, is used solely to interact with "native" code -- code written in a system-level language like C. There's no Java API for JNI -- the API consists entirely of functions you call from C, C++, or a similar language. How long will it take to learn JNI? That depends on whether you know such a language well. If all you know is Java, learning JNI would obviously be very hard; the most important thing you'd need to learn would be how to work in a language that doesn't have automated garbage collection, and you'd especially have to understand how stack and heap data are different in your native language.

As far as the keypress thing goes, that would require not only knowing another language, but learning about the OS-specific APIs available to that language (for example, the .NET or Win32 APIs on Windows.) You'd have to learn how to do the keyboard thing in C, write the code for it, and then write the JNI code to allow you to connect it to Java.

There are commercial products that allow you to call of the Windows API from Java directly -- all the JNI magic is already done for you. But as I said, these are commercial products and somehow I'm guessing that's not going to work for you.

Sun used to have a nice JNI tutorial online, but they took it down; not sure why. There's an Addison-Wesley book, "Programming for the Java Virtual Machine" which is probably the best way to learn JNI.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is JNI and what are the advantages of JNI?
 
Similar Threads
Java calls to RPG functions
question about Servlets
Language Support in Java
java OS?
Excel add-in (VB code) to java