1 class HelloWorld { hello(String input)2 private static native String hello(String input); helloByte(byte[] input)3 private static native byte[] helloByte(byte[] input); factAndCallMeBack(int n, HelloWorld callback)4 private static native void factAndCallMeBack(int n, HelloWorld callback); 5 counterNew(HelloWorld callback)6 private static native long counterNew(HelloWorld callback); counterIncrement(long counter_ptr)7 private static native void counterIncrement(long counter_ptr); counterDestroy(long counter_ptr)8 private static native void counterDestroy(long counter_ptr); 9 asyncComputation(HelloWorld callback)10 private static native void asyncComputation(HelloWorld callback); 11 12 static { 13 System.loadLibrary("mylib"); 14 } 15 main(String[] args)16 public static void main(String[] args) { 17 18 String output = HelloWorld.hello("josh"); 19 System.out.println(output); 20 byte[] outputByte = HelloWorld.helloByte("byte".getBytes()); 21 System.out.println(outputByte); 22 23 24 HelloWorld.factAndCallMeBack(6, new HelloWorld()); 25 26 long counter_ptr = counterNew(new HelloWorld()); 27 28 for (int i = 0; i < 5; i++) { 29 counterIncrement(counter_ptr); 30 } 31 32 counterDestroy(counter_ptr); 33 34 System.out.println("Invoking asyncComputation (thread id = " + Thread.currentThread().getId() + ")"); 35 asyncComputation(new HelloWorld()); 36 } 37 factCallback(int res)38 public void factCallback(int res) { 39 System.out.println("factCallback: res = " + res); 40 } 41 counterCallback(int count)42 public void counterCallback(int count) { 43 System.out.println("counterCallback: count = " + count); 44 } 45 asyncCallback(int progress)46 public void asyncCallback(int progress) { 47 System.out.println("asyncCallback: thread id = " + Thread.currentThread().getId() + ", progress = " + progress + "%"); 48 } 49 } 50