skip to main content

Converting Java Source Code to Object-oriented COBOL : Known cases of Java syntax that is not directly translatable to COBOL : The .class Syntax

The .class Syntax
In Java, if the type is available but there is no instance then it is possible to obtain a Class by appending ".class" to the name of the type. An equivalent short syntax is not available in isCOBOL. In order to obtain the Class of an object, you can rely on the forName() static method exposed by java.lang.Class.
The following Java example:
import java.io.File;
public class FilePackage {
    public static void main (String[] args){
        System.out.println(File.class.getPackage());
is translated to isCOBOL as follows:
       program-id. FilePackage.
       configuration section.
       repository.
           class JClass  as "java.lang.Class"
           class JFile   as "java.io.File"
           class JSystem as "java.lang.System"
       procedure division.
                    (JClass:>forName("java.io.File"):>getPackage())
           catch exception
Because the syntax JFile:>class would not be compiled.
Note that, due to the use of the forName() method, a exception block is required.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left