---
description: >-
  This chapter introduces the JNI-Plugin, which is responsible for supporting
  the Java when using the ApertusVR library, and is used by the Android apps to
  cooperate with ApertusVR.
---

# Java Native Interface

### The Java Native Interface

The Java Native Interface (JNI) is a native language support, which allows Java code (running on JVM) to interoperate with applications and libraries written in C and C++. JNI provides a one-way access to call C/C++ functions from Java. Therefore it helps to use ApertusVR's features from Java codes, which is indispensably important, when programming on Android.

![](https://4044724383-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEyKyxZqxfQ560k-THK%2F-MES5YbaLPHe5sYbJaFR%2F-MESB0fF80Cws5cYVge5%2FJNI.svg?alt=media\&token=f19cf566-de85-43d8-b390-39666bc84a3a)

To learn more about the JNI interface see the official documentation on [Oracle's website](https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/jniTOC.html). For an easy to follow tutorial check [NTU Signapore's guide](https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html).

### Overview of the plugin

ApertusVR uses the JNI language support as a **plugin**, which helps distribute the events, and implements wrapper functionality for ApertusVR entities. The _JNI-plugin_ consists of three layers:

1. The C++ layer (apeJNIPlugin shared library)
2. Java static native functions (ApertusJNI.java)
3. Wrapper classes (ape\<CppClassName>.java)

#### 1. The C++ layer

This layer is an ordinary ape::IPlugin implementation, which gather the events into its event queue, then when somebody calls the appropriate function in Java (`ApertusJNI.processEventDoubleQueue()`), the plugin fires the events on the Java side, using the JNI's callback possibilities.

#### 2. ApertusJNI

This is a static Java class, which contains the Java "headers" of the C++ JNI functions, and everything else needed to use the plugin in Java.&#x20;

#### 3. Wrapper classes

For each subclass of `ape::Entity` in ApertusVR, there is a corresponding Java class (the `ape::Entity` is also included), which provides an interface to access, query, and modify an object on the C++ side. These wrapper classes contains only a `String`, and a `apeEntity.Type` member variables, which makes it available to identify the entity related to the interface object. Then it calls the `static native`functions in ApertusJNI, to access the entity in C++.

