Creating and initializing instances of classes

Before you can use the instance methods that are defined in a Java™ or COBOL class, you must first create an instance of the class.

To create a new instance of class class-name and to obtain a reference object-reference to the created object, code a statement of the following form, where object-reference is defined in the DATA DIVISION of the client:


INVOKE class-name NEW . . . RETURNING object-reference

When you code the INVOKE . . . NEW statement within a method, and the use of the returned object reference is not limited to the duration of the method invocation, you must convert the returned object reference to a global reference by calling the JNI service NewGlobalRef:


Call NewGlobalRef using by value JNIEnvPtr object-reference 
                  returning object-reference

If you do not call NewGlobalRef, the returned object reference is only a local reference, which means that it is automatically freed after the method returns.

related references  
INVOKE statement (Enterprise COBOL for z/OS® Language Reference)