Jump to content

Talk:Java Native Interface

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sigmundur (talk | contribs) at 11:00, 9 February 2011 (error in example?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconJava Start‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.

noncompliant - Article is a tutorial, violates WP:NOT

This 'article' is a tutorial on the use of JNI. WP:NOT prohibits tutorials:

Instruction manuals - while Wikipedia has descriptions of people, places, and things, Wikipedia articles should not include instruction - advice ( legal, medical, or otherwise), suggestions, or contain "how-to"s. This includes tutorials, walk-throughs, instruction manuals, video game guides, and recipes.

(my emphasis).

Suggest reverting to 5 December 2005 edit by 212.85.24.83, which is the most recent edit before the tutorial content was added. LVC 12:16, 25 July 2006 (UTC)[reply]

One week has passed with no challenge on this - reverting. LVC 03:40, 2 August 2006 (UTC)[reply]
You removed too much useful information. I think reverting was a bad idea. It was probably better to just remove the walkthrought --Felipe Monteiro de Carvalho 19:03, 5 August 2006 (UTC)[reply]
As writer of the expansion of the article (stub), I was not aware of this Wikipedia policy at the time I wrote it. I have written it this way because JNI is hard to understand, even for advanced programmers who have never done something like this before. By providing an example, the programmer have a concrete example to work with. There is a ton of useful information on that article that I think will help others master JNI. I will rewrite the article that will not follow a sort of a "tutorial" style format, I will instead just provide a straight-up example, explains the inner mechanisms and provide a link to a proper tutorial if the reader needs to be. - User:AverageAmerican 12 August 2006
I have gotten rid of the walkthrough. I will see if I can write a more appropriate example that will conform to Wikipedia standards. In the meantime I have provided a link to CodeProject.com and Java.sun.com discussing how JNI is used. - User:AverageAmerican 12 August 2006
Thanks for the valuable info! Unfortunately wikipedia admins are too rigorous. I don't know either why this guideline is needed. I wouldn't mind if Wikipedia would contain practical information as well. --80.98.75.217 (talk) 11:56, 14 January 2008 (UTC)[reply]

Is JNI an API or no?

The article reads at the first line, "The Java Native Interface (JNI) is a programming framework..." Then later on it states, "as mentioned before, the JNI is not an easy API to learn." Is JNI properly referred to as an API? I realize that API stands for "application program interface" which fairly describes JNI, but my understanding is that the term API usually refers to a hardware or operating system hook rather than a generic application-to-application communication pathway. Just curious. Thx.

To call and be called ?

The first sentence says JNI allows java code "to call and be called by native applications". Is there and example/tutorial anywhere on the web, showing java code being called by a native application? All the JNI examples I've been reading just show things happening the other way round (java invokes native). -- Harry Wood 17:00, 6 March 2007 (UTC)[reply]

Yes, native applications can invoke the java side - it can even create java objects and pass them on to java. It's more difficult of course, but it's most definately possible. You can take a look at http://www.iam.ubc.ca/guides/javatut99/native1.1/implementing/method.html hope this helps --AverageAmerican 00:49, 8 May 2007 (UTC)[reply]
Indeed, I've just done it in my code. It definitely works :) --81.97.123.218 (talk) 23:27, 26 September 2009 (UTC)[reply]

Examples falls into the pit

The last "pitfall" listed warns against using GetStringUTFChars since it results in "modified UTF-8" (a link to into the the UTF-8 article would be nice). Then a number of examples are presented, and several falls right into this "pit". Shouldn't the examples be rewritten?

error in example?

This puzzles me:

JNIEnv *env;
(*g_vm)->AttachCurrentThread (g_vm, (void **) &env, NULL);

It's clearly from legitimate source but I get warning

warning: passing argument 2 of '(*g_javaVM)->AttachCurrentThread' from incompatible pointer type
note: expected 'const struct JNINativeInterface ***' but argument is of type 'void **'

If I remove (void **) cast, warning goes away. It's not quite clear to me why the cast is there. I use gcc (Debian 4.4.5-10) 4.4.5. --Sigmundur (talk) 10:58, 9 February 2011 (UTC)[reply]