tags:

views:

47

answers:

2

hi all is it possible to declare to native methods in java so that one method is defined in c and other method is defined in c++.m getting confusion in it . please help me in this.

+1  A: 

Yes. As long as the interface uses the standard C calling convention, Java doesn't really care in which language it's implemented. That means you have to surround the declarations in an extern "C" block if you happen to be writing C++:

#include <jni.h>
#ifdef __cplusplus
extern "C" {
JNIEXPORT jstring MyNativeMethod(JNIEnv *, jobject);
}
#endif

It's up to you whether to implement MyNativeMethod in C, C++ or any other language.

Of course, this is already done for you in the header file generated by javah, extern "C" and all.

Pedro d'Aquino
A: 

You don't define native methods in Java. You define the interface but the actual methods remain outside of your Java application.

Putting a Java Interface on your C, C++, or Fortran Code

Saul