Writing object-oriented programs

When you write an object-oriented (OO) program, you have to determine what classes you need and the methods and data that the classes need to do their work.

OO programs are based on objects (entities that encapsulate state and behavior) and their classes, methods, and data. A class is a template that defines the state and the capabilities of an object. Usually a program creates and works with multiple object instances (or simply, instances) of a class, that is, multiple objects that are members of that class. The state of each instance is stored in data known as instance data, and the capabilities of each instance are called instance methods. A class can define data that is shared by all instances of the class, known as factory or static data, and methods that are supported independently of any object instance, known as factory or static methods.

Using Enterprise COBOL, you can:

  • Define classes, with methods and data implemented in COBOL.
  • Create instances of Java™ and COBOL classes.
  • Invoke methods on Java and COBOL objects.
  • Write classes that inherit from Java classes or other COBOL classes.
  • Define and invoke overloaded methods.

In Enterprise COBOL programs, you can call the services provided by the Java Native Interface (JNI) to obtain Java-oriented capabilities in addition to the basic OO capabilities available directly in the COBOL language.

In Enterprise COBOL classes, you can code CALL statements to interface with procedural COBOL programs. Thus COBOL class definition syntax can be especially useful for writing wrapper classes for procedural COBOL logic, enabling existing COBOL code to be accessed from Java.

Java code can create instances of COBOL classes, invoke methods of these classes, and can extend COBOL classes.

It is recommended that you develop and run OO COBOL programs and Java programs in the z/OS® UNIX environment.

Restrictions:

  • COBOL class definitions and methods cannot contain EXEC SQL statements and cannot be compiled using the SQL compiler option.
  • COBOL class definitions and methods cannot contain EXEC SQLIMS statements and cannot be compiled using the SQLIMS compiler option.
  • COBOL programs that use object-oriented syntax for Java interoperability cannot contain EXEC CICS statements, and cannot be run in CICS®. They cannot be compiled using the CICS compiler option.

Example: accounts

related references  
The Java Language Specification