Java Reference
In-Depth Information
FIGURE 2.3
“Hello World!” in the applet viewer.
Experiment with this applet as well. You can make the changes in the text edi-
tor, then recompile and execute the program in the DOS command window. You
will need to exit the applet viewer every time you run your program by clicking the
X widget at the top right of the applet viewer window. Or, you can use the Reload
function in the applet menu.
Change the message from “Hello World!” to “Watson come here!”
What happens if you add a second g.drawString statement to your program?
Why do you think only one message showed up? (Hint: drawString is a graph-
ically oriented function, whereas println is a line-oriented function.)
What do you think the numbers 5, 25 control on the page?
What happens if you change the 5 to a 6?
What happens if you change the 25 to a 35?
Now that you've had some success with your first Java program, let's take a
minute to discuss some of the rules of the road that a Java program must observe.
C LASSES AND F ILENAMES
Java source filenames and public Java class names must all have the same name. The
compiler automatically creates a class file with the same name as the source file.
Consider the first example class, HelloWorld (refer to Figure 2.1).
Search WWH ::




Custom Search