Previous Topic Next topic Print topic


Program Structure - in COBOL and Java

Program Structure in Managed COBOL

class-id HelloWorld as "Hello.Helloworld".

method-id main static.
local-storage section.
01 helloString string value "COBOL".
procedure division using by value args as string occurs any.

    if length of args > 0
        set helloString to args(1)
    end-if
    display "Hello, " & helloString & "!"

end method.

end class. 

Program Structure in Java

package Hello;

public class HelloWorld
{
    public static void main(String[] args) 
    {
        String helloString = "Java";
        if (args.length > 1) 
        {
            helloString = args[0];
        }
        System.out.println("Hello, " + helloString + "!");
    }
}

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.

Previous Topic Next topic Print topic