Enterprise COBOL provides object-oriented syntax to facilitate interoperation of COBOL and Java programs.
You can use object-oriented syntax to:
Basic Java-oriented object capabilities are accessed directly through COBOL language. Additional capabilities are available to the COBOL programmer by calling services through the Java Native Interface (JNI), as described in the Enterprise COBOL Programming Guide.
Java programs can be multithreaded, and Java interoperation requires toleration of asynchronous signals. Therefore, to mix COBOL with these Java programs, you must use the thread enablement provided by the THREAD compiler option, as described in the Enterprise COBOL Programming Guide.
Java String data is represented at run time in Unicode. The Unicode support provided in Enterprise COBOL with the national data type enables COBOL programs to exchange String data with Java.
The following are the entities and concepts used in object-oriented COBOL for Java interoperability:
You create object instances using the NEW operand of the COBOL INVOKE statement or using a Java class instance creation expression.
Object instances are automatically freed by the Java runtime system's garbage collection when they are no longer in use. You cannot explicitly free individual objects.
COBOL instance methods are equivalent to public nonstatic methods in Java.
You execute instance methods on a particular object instance by using a COBOL INVOKE statement or a Java method invocation expression.
COBOL instance data is equivalent to private nonstatic member data in a Java class.
The state of an object also includes the state of the instance data introduced by inherited classes. Each instance object has its own copy of the instance data defined within its class definition and its own copy of the instance data defined in inherited classes.
You can access COBOL object instance data only from within COBOL instance methods defined in the class definition that defines the data.
You can initialize object instance data with VALUE clauses or you can write an instance method to perform custom initialization.
COBOL factory methods are equivalent to public static methods in Java.
You execute COBOL factory methods from COBOL using an INVOKE statement that specifies the class-name as the first operand. You execute them from a Java program using a static method invocation expression.
A factory method cannot operate directly on instance data of its class, even though the data is described in the same class definition; a factory method must invoke instance methods to act on instance data.
COBOL factory methods are typically used to define customized methods that create object instances. For example, you can code a customized factory method that accepts initial values as parameters, creates an instance object using the NEW operand of the INVOKE statement, and then invokes a customized instance method passing those initial values as arguments for use in initializing the instance object.
COBOL factory data is equivalent to private static data in Java.
There is a single copy of factory data for a class. Factory data is associated only with the class and is shared by all object instances of the class. It is not associated with any particular instance object. A factory data item might be used, for example, to keep a count of the number of instance objects that have been created.
You can access COBOL factory data only within COBOL factory methods defined in the same class definition.
A COBOL class must inherit from exactly one parent class, which can be implemented in COBOL or Java.
Every COBOL class must inherit directly or indirectly from the java.lang.Object class.
With the exception of the COPY and REPLACE statements and the END CLASS marker, the statements, entries, paragraphs, and sections of a COBOL class definition are grouped into the following structure:
The end of a COBOL class definition is indicated by the END CLASS marker.
The following is the format for a COBOL class definition.
Format: COBOL class definition >>-+-IDENTIFICATION-+--DIVISION.--CLASS-ID--.--class-name-1-----> '-ID-------------' >--INHERITS--class-name-2--.------------------------------------> >--+---------------------------------------+--------------------> '-other-identification-division-content-' >--ENVIRONMENT DIVISION.--class-environment-division-content----> >--| Factory-definition |--| Object-definition |----------------> >--+--------------------------+-------------------------------->< '-END CLASS--class-name-1.-' Factory-definition |--+-IDENTIFICATION-+--DIVISION.--FACTORY.----------------------> '-ID-------------' >--+-----------------------------------------------+------------> '-DATA DIVISION.--factory-data-division-content-' >--+------------------------------------------------+-----------> '-PROCEDURE DIVISION.--+-----------------------+-' | .-------------------. | | V | | '---method-definition-+-' >--END FACTORY.-------------------------------------------------| Object-definition |--+-IDENTIFICATION-+--DIVISION.--OBJECT.-----------------------> '-ID-------------' >--+----------------------------------------------+-------------> '-DATA DIVISION.--object-data-division-content-' >--+------------------------------------------------+-----------> '-PROCEDURE DIVISION.--+-----------------------+-' | .-------------------. | | V | | '---method-definition-+-' >--END OBJECT.--------------------------------------------------|