With Java™, you have multiple ways to call code that was written in languages other than Java.
Java Native Interface
One of the ways you can call code written in another language is to implement selected Java methods as 'native methods.' Native methods are procedures, written in another language, that provide the actual implementation of a Java method. Native methods can access the Java virtual machine using the Java Native Interface (JNI). These native methods run under the Java thread, which is a kernel thread, so they must be thread safe. A function is thread safe if you can start it simultaneously in multiple threads within the same process. A function is thread safe if and only if all the functions it calls are also thread safe.
Native methods are a "bridge" to access system functions that are not directly supported in Java, or to interface to existing user code. Use caution when using native methods, because the code that is being called may not be thread safe. ee Use the Java Native Interface for native methods for more information about JNI and ILE native methods.
Java Invocation API
Using the Java Invocation API, which is also a part of the Java Native Interface (JNI) specification, allows a non-Java application to use the Java virtual machine. It also allows the use of Java code as an extension of the application.
i5/OS™ PASE native methods
The iSeries™ Java virtual machine (JVM) now supports the use of native methods running in the i5/OS PASE environment. i5/OS PASE native methods for Java enables you to easily port your Java applications that run in AIX® to your iSeries server. You can copy the class files and AIX native method libraries to the integrated file system on the iSeries nd run them from any of the control language (CL), Qshell or i5/OS PASE terminal session command prompts.
Teraspace native methods
The iSeries Java virtual machine (JVM) now supports the use of teraspace storage model native methods. The teraspace storage model provides a large process, local-address environment for ILE programs. Using teraspace allows you to port native method code from other operating systems to i5/OS with little or no changes to your source code.
java.lang.Runtime.exec()
You can use java.lang.Runtime.exec() to call programs or commands from within a Java program. The exec() method starts another process in which any iSeries program or command can run. In this model, you can use standard in, standard out, and standard err of the child process for interprocess communication.
Interprocess communication
One option is to use sockets for interprocess communication between the parent and child processes.
You can also use stream files for communication between programs. Or see interprocess communication examples for an overview of your options when communicating with programs that are running in another process.
To call Java from other languages, see Example: Call Java from C or Example: Call Java from RPG for more information.
You can also use the IBM® Toolbox for Java to call existing programs and commands on the iSeries server. Data queues and iSeries messages are usually used for interprocess communication with the IBM Toolbox for Java.