Evaluating the Java Native Interface (JNI): Data Types and Strings

Evaluating the Java Native Interface (JNI): Data Types and Strings

Stelios Sotiriadis (The Edward Rogers Sr. Department of Electrical and Computer Engineering, University of Toronto, Toronto, Canada), Oladotun Omosebi (Department of Computer Science, Edge Hill University, Lancashire, UK), Assem Ayapbergenova (Department of Information Technologies, Satbayev University, Almaty, Kazakhstan) and Nurbek P. Saparkhojayev (Department of Information Technologies, Satbayev University, Almaty, Kazakhstan)
Copyright: © 2018 |Pages: 12
DOI: 10.4018/IJDST.2018040103

Abstract

This article describes how the java native interface (JNI) is a powerful feature of the java platform that started to draw attention in the latter years as an efficient programming framework for building and delivering innovative technological applications based on disruptive technologies such as mobile, Internet of Things and embedded systems. Developers use it to incorporate native code written in programming languages such as C, C++, python etc., into java. JNI is particularly useful when java applications need to access existing native libraries or code blocks written in other languages to increase performance, avoid recoding and expand interoperability between programming languages for processes that reside in the same process. This article aims to explore JNI features and to discover fundamental operations of the Java programming language, such as arrays, objects, classes, threads and exception handling, and to illustrate these by using various algorithms and code samples.
Article Preview

Introduction

The Java Native Interface (JNI, 2014) aims to provide interoperability between Java code running on Java Virtual Machine (JVM) and code written in other programming languages like C, C++, assembly, python and others. It is typically used for utilizing certain platform depended features, for reusing existing libraries and for speeding up time critical execution of applications. Using the JNI, developers implement Java classes that are extended with native methods and linked dynamically. This is possible, for instance, by using shared objects, as in UNIX systems or Dynamic-Link Library (DLL) extensions on Windows systems. Today, with the increasing amount of applications and disruptive based innovative services like mobile applications, cloud platforms, Internet of Thing (IoT) sensor protocols and development suites, the utilization of the JNI concept becomes once more essential (Sun et al., 2013). According to Dawson et al. (2015), JNI can be a key element for leveraging existing code assets in a service-oriented architecture (SOA) or cloud-based system. JNI is crucial for utilizing and interacting with libraries specific to platforms of embedded systems as it enables access to faster execution of native programs (Lee et al., 2011). This will offer a significant advantage by speeding up the development process, avoiding the reproduction of already developed code and thereby, increasing performance (Chandrian, 2011)

Using JNI, a Java application invokes native methods, submits parameters and obtains results after the native method has finished processing. The latter can both create and invoke operations on existing Java objects to: (a) create, update and inspect Java objects, (b) get any primitive data types or objects, (c) return either Java primitive data types or objects back to the Java program, (d) call Java instance or class methods, pass it the required parameters and get the results back when the method completes, (e) catch and throw Java exceptions and, (f) implement synchronization to support multithreaded access to a running JVMs.

There are various ways in which a Java application can communicate with a native application. These include using a TCP/IP connection, and via Inter-Process Communications (IPC) mechanisms etc. (Stenman & Sagonas, 2009). A Java application may also connect to a legacy system via a database using standard Java API, or by utilizing distributed objects such as RPC or Java IDL API (Sperko, 2003). However, in the aforementioned cases the native code resides in different processes. Having said that, the contribution of this work focuses on exploring JNI features that are essential for cases in which a Java application will need to communicate with native code that resides in the same process (Android M Developer, 2015, Liang, 1999). This has been proposed as an efficient solution for mobile application platforms, such as the Android platform, to load code from dynamic shared libraries. In particular, from the perspective of disruptive technologies, the benefits of using JNI includes the fact that both the calling program and the called program share the same process, while still allowing other methods to start new processes. By this method JNI provides faster calls and consumes less resources.

Complete Article List

Search this Journal:
Reset
Open Access Articles
Volume 10: 4 Issues (2019): Forthcoming, Available for Pre-Order
Volume 9: 4 Issues (2018): 3 Released, 1 Forthcoming
Volume 8: 4 Issues (2017)
Volume 7: 4 Issues (2016)
Volume 6: 4 Issues (2015)
Volume 5: 4 Issues (2014)
Volume 4: 4 Issues (2013)
Volume 3: 4 Issues (2012)
Volume 2: 4 Issues (2011)
Volume 1: 4 Issues (2010)
View Complete Journal Contents Listing