-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample1.java
More file actions
55 lines (47 loc) · 1.75 KB
/
Sample1.java
File metadata and controls
55 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.net.URL;
import java.net.URLClassLoader;
import java.util.StringTokenizer;
public class Sample1
{
static {
System.err.println("debugging info: classloader:");
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url: urls){
System.err.println(url.getFile());
}
System.err.println("\njava.library.path:");
String property = System.getProperty("java.library.path");
StringTokenizer parser = new StringTokenizer(property, ";");
while (parser.hasMoreTokens()) {
System.err.println(parser.nextToken());
}
System.err.println();
try {
//System.load("./Sample1.so");
System.loadLibrary("Sample1");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public native int intMethod(int n);
public native boolean booleanMethod(boolean bool);
public native String stringMethod(String text);
public native int intArrayMethod(int[] intArray);
public static void main(String[] args)
{
Sample1 sample = new Sample1();
int square = sample.intMethod(5);
boolean bool = sample.booleanMethod(true);
String text = sample.stringMethod("To be or not to be");
long d = -System.nanoTime();
int sum = sample.intArrayMethod(new int[] {1,1,2,3,5,8,13} );
d += System.nanoTime();
System.out.println("intMehod: " + square);
System.out.println("booleanMehod: " + bool);
System.out.println("stringMehod: " + text);
System.out.println("intArrayMehod: " + sum);
System.out.println("Time for intArrayMethod in nano seconds: " + d );
}
}