Java Programming/Invoking C

You can use  method to invoke a program from within a running Java application. also allows you to perform operations related to the program, such as control the program's standard input and output, wait until it completes execution, and get its exit status.

Here's a simple C application that illustrates these features. This C program will be called from Java:

This application writes a string "testing" to standard output, and then terminates with an exit status of 0. To execute this simple program within a Java application, compile the C application:

Then invoke the C program using this Java code:

The demo calls a method  to actually run the program.

This method hooks an input stream to the program's output stream, so that it can read the program's output, and save it into a list of strings.

Migrating C to Java
Tools exist to aid the migration of existing projects from C to Java. In general, automated translator tools fall into one of two distinct kinds:
 * One kind converts C code to Java byte code. It is basically a compiler that creates byte code. It has the same steps as any other C compiler. See also C to Java JVM compilers.
 * The other kind translates C code to Java source code. This type is more complicated and uses various syntax rules to create readable Java source code. This option is best for those who want to move their C code to Java and stay in Java.