 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between a Java method and a native method?
A native method is the one whose method implementation is done in other languages like c++ and Java. These programs are linked to Java using JNI or JNA interfaces.
The difference between normal method and native method is That the native method declaration contains native keyword and, the implementation of the method will be other programming language.
Example
Tester.java
 public class Tester { public native int getValue(int i); public static void main(String[] args) { System.loadLibrary("Tester"); System.out.println(new Tester().getValue(2)); } }  Tester.c
 #include <jni.h> #include "Tester.h" JNIEXPORT jint JNICALL Java_Tester_getValue( JNIEnv *env, jobject obj, jint i) { return i * i; }  Compile and run
 javac Tester.java javah -jni Tester gcc -shared -fpic -o libTester.so -I${JAVA_HOME}/include \ -I${JAVA_HOME}/include/linux Tester.c java -Djava.library.path=. Tester   Output
4
Advertisements
 