I recently experimented with JNI to port some existing C ++ libraries.
As part of my testing, I created a simple helloworld program. I call a simple built-in function in C ++ that simply prints messages. I'm a little curious about the behavior I observed during the execution of the program - it seems that all messages and answers to functional functions are printed after Java System.out.print
. Is it because native calls are made after Java calls, or am I just ignoring this behavior?
public static void main(String[] args) { HelloWorld app = new HelloWorld(); System.out.println("say"); app.print(); System.out.println("what"); app.print(); }
The result is as follows:
say what hola, world ! hola, world !
The native function is as follows:
Java_HelloWorld_print(JNIEnv *env, jobject obj) { printf("hola, world !\n"); return; }
source share