Introduction to Java Native Interface (JNI) for Beginners
A beginner's quiz on using Java Native Interface (JNI) to interface with C/C++.
Questions in this quiz
15 questions on Introduction to Java Native Interface (JNI) for Beginners. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of Java Native Interface (JNI)?
- ATo enable Java applications to run on any operating system without modification
- BTo compile Java code into native machine code
- CTo allow Java code to call or be called by native applications and libraries written in C/C++
- DTo convert Java bytecode into C++ code
2.Which keyword is used in Java to declare a native method?
- Aextern
- Bforeign
- Cnative
- Dimport
3.What file extension is typically used for a shared library on Windows?
- A.dll
- B.so
- C.lib
- D.dylib
4.Which function is used to load a native library in Java?
- ALibrary.load()
- BNative.load()
- CSystem.loadLibrary()
- DRuntime.loadLibrary()
5.In JNI, what is the role of the 'javah' tool?
- ATo convert C++ code into Java bytecode
- BTo compile Java code into native code
- CTo execute Java applications with native code
- DTo generate C/C++ header files from Java classes
6.Which of the following is NOT a valid JNI data type?
- Ajstring
- Bjint
- Cjfloat
- Djchararray
7.What is the JNI function used to obtain a pointer to the JVM environment?
- AAttachCurrentThread()
- BFindClass()
- CGetEnv()
- DGetJavaVM()
8.Which JNI function is used to find a Java class from native code?
- ALoadClass()
- BFindClass()
- CLocateClass()
- DGetClass()
9.What is the correct way to declare a native method in Java?
- Apublic void native methodName();
- Bvoid public native methodName();
- Cpublic native void methodName();
- Dnative public void methodName();
10.Which JNI function is used to call a Java method from native code?
- ACallVoidMethod()
- BInvokeMethod()
- CRunMethod()
- DExecuteMethod()
11.What is the JNI function to release a Java string obtained in native code?
- ADeleteString()
- BDisposeString()
- CReleaseStringUTFChars()
- DFreeString()
12.Which JNI function is used to create a new Java object from native code?
- ANewObject()
- BBuildObject()
- CCreateObject()
- DInstantiateObject()
13.What is the JNI function used to throw an exception from native code?
- AThrow()
- BRaiseException()
- CThrowException()
- DRaiseError()
14.Which JNI function is used to get the length of a Java array?
- AArraySize()
- BLengthOfArray()
- CSizeOfArray()
- DGetArrayLength()
15.What is the JNI function used to access elements of a Java int array?
- AGetIntArrayElements()
- BFetchIntArray()
- CRetrieveIntArray()
- DAccessIntArray()