COBOL Calling Static Java Methods

Native COBOL programs can interoperate with static Java methods through a specific syntactical argument of the CALL statement, where you supply the package, class(es), and method names; for example:

...
CALL "Java.com.mf.widgets$Timers.Clock2.Alarm1" using grp1 returning res-1
...

where com.mf.widgets is the package to which the class belongs, Timers is the name of the outer class, Clock2 is the name of the method's containing class, and Alarm1 is the name of the static method being called. The argument being passed into the method is grp1, and the method returns a value to res-1; both of these arguments are mapped to compatible Java types, as per Mapping COBOL Items and Java Types, otherwise an error is generated during compilation.

The Compiler automatically recognizes the call as one to a Java method when it encounters the 'Java' prefix in the call literal, which then invokes the process, under the covers, that maps the Java types and then identifies and runs the method that corresponds to the generated method signature. .

The process also supports method overloading, where the class being called has a number of different implementations of a particular method. The number and types of argument supplied in the CALL statement will determine the method used.

Certain arguments will cause an error on compilation (COBCH2330) if the COBOL item maps to a primitive or immutable Java type (char, String, BigDecimal, etc...) is passed BY REFERENCE, as the Java program cannot change the value of these types; however, you can pass an array of one of these mutable types; for example:
01 num1 pic 9(9) comp-5 occurs 10.

which maps to an int[10].

For a working example of a COBOL program calling a Java static method, from the command line, see Example 1 - COBOL Calling Java Static Methods. For similar examples from within the IDE, see Java Interoperability within the IDE.