Contents Previous Next
Html--+--Hello.html (an HTML file you create) | +--classes--+--HelloWorld.java (a Java source file you create) | +--HelloWorld.class (created by the compiler)
Important: Do NOT invoke hotjava from the classes directory. Due to a bug, HotJava can't reload an applet (for example, after you make changes to its code) when you invoke hotjava from the directory that contains the applet's compiled code.
import browser.Applet; import awt.Graphics; class HelloWorld extends Applet { public void init() { resize(150, 25); } public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); } }Note: When creating the Java source files, be sure to use an editor that can save files with mixed-case names and 4-letter suffixes.
Details of creating an Applet subclass (which is what the above code does) are discussed elsewhere in this document. To see implementations of Applet subclasses, look at the code examples.
If compilation succeeds, the compiler creates a file named HelloWorld.class. If compilation fails, make sure you typed in and named the program exactly as shown above. See the Java compiler documentation for more information on compiling Java code, and the Java Language Specification for information on the Java language.
<HTML> <HEAD> <TITLE> A Simple Program </TITLE> </HEAD> <BODY> Here is the output of my program: <APP CLASS="HelloWorld"> </BODY> </HTML>The APP HTML tag (which you use to add applets to a page) is discussed later in this document.
file:/home/kwalrath/Html/Hello.htmlor, for files on Windows NT:
file:///c:/Html/Hello.htmlInformation on URLs is available in various places on the Internet, such as from the NCSA in A Beginner's Guide to URLs.
Contents Previous Next