Here is a simple group called TheDate:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TheDate.
02 CurrentYear PIC 9(4).
02 CurrentMonth PIC 99.
02 CurrentDay PIC 99.
You can approximate this group of three variables in a Java program with a class
definition:
class TheDate {
String currentYear;
String currentMonth;
String currentDay;
}
The differences are primarily that the COBOL group defines actual storage
space and the exact memory layout ("picture") whereas the Java class
definition describes a template for storage rather than the storage itself. A
running Java program is a collection of objects. Objects with the same
characteristics and behavior are described by the same class. Objects of the
same type (class) are therefore considered instances of that class. To
allocate actual storage for an object, use the new operator:
// make d refer to a TheDate type object.
TheDate d = new TheDate();
A better way to look at the difference between a class and an
object is, perhaps, the difference between a FILE and a
RECORD. A record is a collection of fields and a file is a
collection of records. There is only one record definition, but there
may be many records within a file with that same structure.
Similarly, for any class definition, there may be many class
instances, objects. The type (class) defines the structure of the
object and the object stores the content.
On the other hand, COBOL reads files one record at a time--there is
exactly one record from a file in memory at once (the "record buffer"). In a
Java runtime environment, the instances of a class all exist in memory at once. If you want 3000
TheDate objects, you have to have enough memory to hold 3000 of
these objects.
The following file descriptor entry describes a student file with a record
structure specified in the StudentRecord group.
DATA DIVISION.
FILE SECTION.
FD StudentFile.
01 StudentRecord.
02 StudentId PIC 9(7).
02 StudentName.
03 Surname PIC X(8).
03 Initials PIC XX.
You can imagine that the records in the file are like "freeze-dried" Java
objects; that is, they are on the disk instead of in memory.
Sometimes you have a COBOL file containing records of different
record types. Because you cannot always establish the record type just by
examining its contents, you normally put a special data item at the start of
each record indicating the record or transaction type.
FD TransactionLogFile.
01 StudentRecord.
02 RecordType PIC X.
...
The Java runtime environment has a similar notion for objects. You can ask every object for its
type. The type information refers to the object's class definition, which
includes the list of methods, data fields, and so on.
copyright 1996-2000 Magelang Institute dba jGuru