The native keyword is a modifier in Java that is applied to a method to indicate that the method is implemented in native code (other than Java such as C, C++, and assembly) using JNI (Java Native Interface).
Native methods cannot have bodies and must end with semicolons.
The native keyword is applicable only for methods, and we can’t apply it anywhere else.
A method marked with the native keyword is one that is implemented in platform-dependent code.
Syntax of native keyword
[ public | protected | private] native [return_type] method_name (parameters);
Java Native Interface (JNI)
The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.
JNI imposes no restrictions on the implementation of the underlying Java VM. Therefore, Java VM vendors can add support for the JNI without affecting other parts of the VM.
Example: Native keyword in Java
Advantages of Native Keyword in Java
Helps to integrate other programming language (like C, C++) existing code with Java Application.
Access system or hardware resources that are only reachable from the other language.
Dynamically call a pre-loaded library (non-java code) using an arbitrary driving code written in JAVA and still get a response in JAVA.
Improves the over all performance of the system.
Avail the unique features of other programming language like C, C++ etc. and interage it with Java.
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
Please share this article on social media to help others.
If you have any query or suggestion regarding this artical please share with us feedback@javabytechie.com