This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.