Wrapper.java
1 2 3 4 5 6 7 8 9 10 11 12 | class Wrapper{ static { System.loadLibrary("jni_type"); //libjni_type.so } public native void print(boolean b); //function overloading. //one interface multi method public native void print(char c); public native void print(byte b, short s, int i, long l); public native void print(float f, double d); } |
Main.java
1 2 3 4 5 6 7 8 9 10 11 | class Main{ public static void main(String [] args) { Wrapper wrapper = new Wrapper(); wrapper.print(true); // true, false wrapper.print('A'); wrapper.print( (byte)10, (short)20, 30, 40L);// C case int a = 3.14; // Java case int a = (int) 3.14; wrapper.print( 3.1415F, 2.718); } } |
jni_type.c
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 | #include <stdio.h> #include "Wrapper.h" JNIEXPORT void JNICALL Java_Wrapper_print__Z(JNIEnv *env, jobject obj, jboolean b) { printf("boolean --> unsigned char : %s\n", (b) ? "true" : "false"); // if(b==true) return "turn" } // if(b==false) return "false" JNIEXPORT void JNICALL Java_Wrapper_print__C(JNIEnv *env, jobject obj, jchar c) { printf("char --> unsigned short int : %c\n", (unsigned char)c); // 0 to 255s } JNIEXPORT void JNICALL Java_Wrapper_print__BSIJ(JNIEnv *env, jobject obj, jbyte b, jshort s, jint i, jlong l) { printf("byte --> signed char : %d\n", b); printf("short --> short int : %d\n", s); printf("int --> int : %d\n", i); printf("long --> long long int : %lld\n", l); } JNIEXPORT void JNICALL Java_Wrapper_print__FD(JNIEnv *env, jobject obj, jfloat f, jdouble d) { printf("float --> float : %.2f\n", f); printf("double --> double : %.2f\n", d); } |
'Study > 리눅스' 카테고리의 다른 글
| 리눅스 c언어로 시리얼 통신하기 (0) | 2014.10.30 |
|---|---|
| 프로세서기반 임베디드 리눅스 디바이스 드라이버 (1) (0) | 2014.10.01 |
| 리눅스로 c언어 컴파일하기 Java (1) (0) | 2014.09.19 |
| 리눅스로 c언어 컴파일하기 Linked List (2) (0) | 2014.09.19 |
| 리눅스로 c언어 컴파일하기 Linked List (1) (0) | 2014.09.18 |
