Calling the C$JAVA Routine

An easy, effective way to call Java from COBOL is via the C$JAVA library routine. A call to C$JAVA causes the JVM to be loaded (if it is not already) and the specified Java class to be loaded.

The COBOL statement used to make a call to Java from COBOL has the following syntax:

CALL "C$JAVA" 
      USING OP-CODE, CLASS-NAME, METHOD-NAME, METHOD-SIGNATURE, 
          FIELD-INT, FIELD-RETURN 
       GIVING STATUS-VAL.

For example:

CALL "C$JAVA" 
     USING CJAVA-NEW, "acuCobolGT/CAcuCobol", "()V" 
     GIVING OBJECT-HANDLE.

The default CALL C$JAVA statement is designed to call a Java method. It requires a class name fully qualified with the package name if necessary. It also requires a method name and a method signature describing the parameter types and return types. After the method signature, pass the parameters that the method requires, and finally pass a parameter to hold the Java return value from the method. If the method is void, no return parameter is required. A giving value is returned to pass any other error code that may have occurred.

See C$JAVA for complete information on the C$JAVA library routine and its op-codes.

Note: To call Java from COBOL, HP-UX users must relink the runtime so that it is statically linked to "libjvm.sl". For instructions, see Linking the Runtime to libjvm.sl on HP-UX.