Java Reference
In-Depth Information
4.
Using a text editor, modify and compile your HelloWorld.java source file
in the java4cobol directory. The source file should contain these statements:
public class HelloWorld
{
public static void main(String args[])
{
String tempMsg;
// Our original println statement:
System.out.println("Hello World!");
// Create a new instance of the ErrorMsg class:
ErrorMsg myErrorMsg = new ErrorMsg ();
// Get the value of the text item in ErrorMsg, by calling the getErrorMsg
// method.
tempMsg = myErrorMsg.getErrorMsg ();
// Print the contents of the String returned by this method.
System.out.println (tempMsg);
// Set the text item in ErrorMsg to some text String, and print its // //
// contents.
myErrorMsg.setErrorMsg ("Some Text");
tempMsg = myErrorMsg.getErrorMsg ();
System.out.println (tempMsg);
// Call the setErrorMsg method again to set ErrorMsg to some other text.
myErrorMsg.setErrorMsg ("Some New Text");
tempMsg = myErrorMsg.getErrorMsg ();
System.out.println (tempMsg);
}
}
5.
Now run your program, using the Java runtime that comes with the SDK:
java HelloWorld
If you've done everything correctly, your MS-DOS window should look
like this:
C:>javac ErrorMsg.java
C:>javac HelloWorld.java
C:>java HelloWorld
Search WWH ::




Custom Search