What is Native Interface in JAVA?
Answer
JNI is the mechanism used to invoke methods written in languages such as c and C++. You can write code using language like c and c++ and declare its native methods and can use the same method in java using JNI.
JNI exposes JNI functions and pointers that can access java objects and methods.
What is Native Interface in JAVA?
Java Native Interface permits the developers to integrate the native code such as C or C++ into a java application. To take the advantages of C programming and implementing the Java GUI features together makes the applications more efficient and powerful.
JNI is used to handle situations where the entire application can not be written in java.
Explain the advantages and disadvantages of using JNI.
Answer
Advantages of JNI
Using JNI, we can access c and c++ code which adds performance boost to JAVA.
JNI allows JAVA to access some hardware features using other languages like c and c++.
Disadvantages of JNI
JNI uses native languages which mean it has portability issue.
Code debug is big problem for the developers who use JNI features in JAVA.
Explain the advantages and disadvantages of using JNI.
Advantages:
- Use the existing library that was previously written in another languages.
-Use of windows API functions
-Increasing the speed of execution
-Invoke API functions from server product that is developed in C or C++ from a java client.
Disadvantages:
-Write Once Run Anywhere is not possible
-Run time errors debugging is difficult in native code
- An applet can not call a native method
- Security risk is potential
Explain Exception Handling in JNI.
Answer
JNI exceptions are handled by using the following:
* Throw( )
Throws an existing exception object. Used in native methods to rethrow an exception.
* ThrowNew( )
Creates a new exception object and throws.
* ExceptionOccurred( )
Determines the exception status of throws and not yet cleared.
* ExceptionDescribe( )
Displays the exception and stack trace
* ExceptionClear( )
A pending exception is cleared.
* FatalError( )
Causes a fatal error to raise and does not return.
Comments
Post a Comment