How do you take your Java?
A little dash or a splash of COBOL can make for the perfect mix
isCOBOL allows programmers to take advantage of the best of both COBOL and Java by providing common ground between the two technologies. With isCOBOL, organizations can add the power and flexibility of the Java platform to existing COBOL programs and also make COBOL investments easily accessible to the Java world. This article briefly examines some of the synergies that exist between COBOL and Java technology and includes a few examples to illustrate how COBOL and Java programmers can incorporate each others technologies with the isCOBOL Application Platform Suite.
COmmon Business Oriented Language – 50 Years Young
One of the original design goals for COBOL was to offer a programming language that would be easy to read and understand by managers with no programming training. Although managers rarely took advantage of that -- either fifty years ago or today -- a direct outcome of this goal is that the COBOL language is comprised of familiar English building block structures such as verbs, clauses, sentences, sections, and divisions. The Environment Division, for instance, is a set area found in all COBOL programs that describes the particular environment for which the program is written and all external references, such as to devices, files, currency symbols, and object classes that a COBOL application requires. A COBOL developer looking to move a program to a new platform or region knows that this centralized area of code will have to be reviewed and potentially altered to accommodate the new target platform’s requirements.
COBOL’s straightforward programming approach, clear organizational structure, ability to deal with business logic, adoption of latest technological paradigms, and portability are some of the primary factors that contributed to its widespread adoption and persistence in the industry.
Originally called Green, then changed to Oak, finally known as Java – 15 years mature
The Java programming language leverages small, modular building blocks (known as object classes) that are tied together to form a complete application. Two important concepts in object-oriented programming are encapsulation and inheritance:
- Encapsulation means that a Java class can be viewed as a "black box" whose internal workings are hidden. To use a class it is only necessary to know what the class does, not the details of how the class does it. As long as the public interface stays the same, the internal mechanisms of a class can be improved or the class can be replaced with a different one without impact on other components.
- Inheritance means that new classes can be formed using classes that have already been defined, leveraging and extending their functionality.
Object classes can be easily assembled, disassembled, and reused in new applications as business requirements change. Since Java programs run in any environment that supports the proper Java Runtime Environment (JRE) they are extremely portable and can be moved between platforms without any program code changes.
It is this modularity, portability, and reusability that contribute to the growing adoption of Java programming in the industry today.
COBOL with a dash of Java
With isCOBOL APS, developers can quickly add a wealth of new functionality to COBOL applications by integrating free, reusable, modular solutions found in the Java SE and Java EE Development Kits as well as in various open source communities such as The Apache Software Foundation and SourceForge. Solutions available to Java developers are now equally available to COBOL developers -- the challenge is only to identify the existing Java solution needed for a particular programming task and to write the COBOL code to interface with it.
It is important to emphasize that to integrate these Java solutions, a COBOL programmer does not need to be trained and experienced in the Java language. The programmer’s only requirements are to be able to understand basic object-oriented concepts such as classes and methods, to know how to create an object and invoke a method in COBOL, and to understand how to read and use the Javadocs for the particular Java class to be used. These topics are covered in the isCOBOL APS Language Reference Manual and any beginner's book or online resource on Java programming.
As an example of the new functionality isCOBOL makes available to the COBOL developer, consider the full array of XML APIs and tools available to a Java programmer. To parse local XML files or XML from a URL, a COBOL developer could use the JDOM Java package. Here is a simple program that retrieves an XML document from a URL and parses the XML using JDOM.
Developers can also take advantage of Java interfaces offered by third-party commercial software providers. For example, to add an electronic payment processing feature, a business could choose an electronic payment service provider and request the Java interface. The COBOL developer could use that Java interface directly from COBOL.
Java with a splash of COBOL
With isCOBOL APS, developers can now write programs in COBOL that can be called directly from Java as if they were written in the Java language. Java developers do not need to learn COBOL in order to make use of COBOL assets.
COBOL developers can present their subprograms as POJOs (Plain Old Java Objects). The Java developer receiving the objects needs only to know the class and method names, parameters, and return values to make use of them. The fact that the object class was written in COBOL or that it calls other COBOL subprograms is inconsequential.
The isCOBOL Compiler automatically converts existing COBOL programs into POJOs. No COBOL code changes are required. The COBOL program name becomes the Java class name. The resulting Java class has a "call" method which Java code can invoke to call the COBOL program. If required, the COBOL developer can precisely define the program's object interface using object-oriented COBOL syntax. This COBOL object can accept and return Java data types to make the Java developer's task even easier. For instance, if an organization is looking to integrate with a JEE server and needs to deploy a Servlet, Web Service, or Enterprise JavaBean (EJB), etc. those can all now be created natively in COBOL.
So what does this look like on the ground level to a developer? Let’s look at a few examples.
COBOL and Java Code ExamplesExample 1 – COBOL calling Java
Here is the source code for a COBOL program that uses object-oriented COBOL syntax to access a Java class
java.lang.System and use a Java data type
This example demonstrates the use of the repository paragraph to define COBOL user-words that can be used to reference Java classes. It is also possible to specify the full Java class name when declaring a variable as an object reference. This example shows 3 styles of invoking methods. It shows the ability to use Java data types in COBOL statements taking advantage of the isCOBOL Framework to automatically convert the Java data type to the COBOL type that will work in that statement. This is just one example, any Java class and any Java data type can be used.Example 2 - Java calling COBOL
COBOL developers can write programs in COBOL that can be called directly from Java as if they were written in the Java language. Here is the source code for an object class
isobject written in COBOL.
This class has one method "add1" which takes a Java string and a Java integer, displays them to the standard output stream, adds 1 to the integer, and returns the result. The isCOBOL Compiler will output a file named isobject.class which can be used by the Java developer.
And here is the source code for a Java program which uses the COBOL object
isobject just as if it were written in Java language.
Notice the call to
isobject.add1(PAR1, PAR2) is simple Java code. The IDE used by the Java developer will assist with code completion. Even the IDE doesn't know that
isobject.class was written in COBOL because behind-the-scenes the isCOBOL Compiler converted the COBOL to Java source code.
These are just a few examples of the collaboration and synergy that isCOBOL enables between the COBOL and Java worlds. Making your own perfect mix of COBOL and Java with isCOBOL should be …well, a piece of cake. Enjoy!
Click here to download zip file contains the 3 example COBOL programs mentioned in the article. View the README file for more information after
To arrange code analysis report or to discuss your COBOL migration needs in more detail, email email@example.com.