Tutoriallearn.com

Easy Learning


Home

Search Tutoriallearn.com :



native method

  • The native keyword is used to denote a method is implemented in native code using JNI (Java Native Interface).
  • It is a modifier.
  • It is applicable only for methods.
  • native methods are generally implemented in C, C++.
  • native method is used to improve performance of the system.
  • native methods achieve machine level/memory level communications.
  • It is used for already existing legacy non-java code.

Example

class demo {
	// native keyword is used in method m1
	public native void m1();
	public static void main(String args[]){
		demo d1 = new demo();
		d1.m1();
	}
}
In the above the example, method m1 is declared as native method with the help of native keyword. The native methods are implemented already using non-java languages like C, C++. Therefore, implementation of native methods is provided by third party. Hence, native method deceleration is ended with semi-colon.
  • native methods can not be declared as "abstract".
  • native methods can not be declared as "stricfp".
    Disadvantage of native method is that it breaks platform independent nature of java.






© Copyright 2016-2026 by tutoriallearn.com. All Rights Reserved.