Java Reference
In-Depth Information
The class that contains this method ( HelloWorld , in the example), does not
need to be any particular name, but it may need to be public, depending on the
requirements of the runtime environment. It also must be a static class, mean-
ing only one instance of the class can exist at a time.
The internal name of the class (in the source program HelloWorld.java) and
the external name of the class (the HelloWorld.class file built by the compiler)
must be the same.
A Java application run in this manner does not expect to have a GUI environ-
ment available to it, but it can. It does expect to be able to write to a logical file,
known as standard out , and to read from standard in . These files are more or
less the equivalent of the ACCEPT and DISPLAY verbs that interact with the
CRT in COBOL programs.
For most Windows-based Java interpreters, standard out and standard in are
directed toward an MS-DOS command window. Java applications run this way
are not graphical applications.
The statement System.out.println ("Hello World!"); writes to the console, or
standard out. It performs the println() method in a built-in object named
System.out . This method accepts a String input parameter and writes it to
standard out. Think of it as analogous to this COBOL statement:
DISPLAY "Hello World!".
Subsequent calls to println write a new line of text to standard out.
The next program you wrote was a Java applet .
An applet expects to be supported by some type of graphical hosting environment.
Most often, the graphical hosting environment is a browser.
Some standalone Java runtime environments also provide a built-in graphical
hosting environment, or applet viewer . For the SDK, this was APPLET-
VIEWER.EXE. The applet viewer is an excellent tool for testing your applets.
The main program (the program that gets the ball rolling) with a Java applet is
the hosting environment (the browser or the applet viewer). It calls the paint()
function in your class so that you can display information to the screen. The
paint() function must have a specific interface. It must have a public method
with this method definition:
public void paint(Graphics g)
This method accepts a single parameter. It is a Graphics object (named g in the
example).
Search WWH ::




Custom Search