• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is JNI and what are the advantages of JNI?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic