StringJNICaller.java
1 class StringJNICaller{
2 public native String getUppercaseString(String inpStr);
3
4 public static void main(String args[]){
5 System.loadLibrary("stringlib");
6
7 StringJNICaller sjnic=new StringJNICaller();
8 String uprstr=sjnic.getUppercaseString("hello sri lanka");
9 System.out.println(uprstr);
10 }
11 }
StringJNICaller.h
1 /* DO NOT EDIT THIS FILE - it is machine generated */
2 #include <jni.h>
3 /* Header for class StringJNICaller */
4
5 #ifndef _Included_StringJNICaller
6 #define _Included_StringJNICaller
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 /*
11 * Class: StringJNICaller
12 * Method: getUppercaseString
13 * Signature: (Ljava/lang/String;)Ljava/lang/String;
14 */
15 JNIEXPORT jstring JNICALL Java_StringJNICaller_getUppercaseString
16 (JNIEnv *, jobject, jstring);
17
18 #ifdef __cplusplus
19 }
20 #endif
21 #endif
StringJNICaller.cpp
1 #include "StringJNICaller.h"
2 #include <string.h>
3
4 JNIEXPORT jstring JNICALL Java_StringJNICaller_getUppercaseString(JNIEnv *env, jobject obj, jstring string)
5 {
6 const char *str=env->GetStringUTFChars(string,0);
7 char cap[128];
8 strcpy(cap,str);
9 env->ReleaseStringUTFChars(string,str);
10 return env->NewStringUTF(strupr(cap));
11 }
12
Download Source Codes
References :
[1] http://www.ibm.com/developerworks/java/tutorials/j-jni/section2.html
0 comments:
Post a Comment