Previous | Next | Trail Map | Getting Started | Table of Contents

The "Hello World" Applet

By following the steps on this page, you can create and use an applet. If you aren't interested in applets, you might want to skip ahead to the Writing Java Programs(in the Writing Java Programs trail) trail.

Create a Java Source File

Create a file named with the Java code shown here:
import java.applet.Applet;
import java.awt.Graphics;

public class HelloWorld extends Applet {
    public void paint(Graphics g) {
        g.drawString("Hello world!", 50, 25);

Compile the Source File

Compile the source file using the Java compiler.

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.

Create an HTML File that Includes the Applet

Create a file named Hello.html in the same directory that contains HelloWorld.class. This HTML file should contain the following text:
<TITLE> A Simple Program </TITLE>

Here is the output of my program:
<APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>

Load the HTML File

Load the HTML file into an application that can run Java applets. This application might be a Java-compatible browser or another Java applet viewing program, such as the Applet Viewer provided in the JDK. To load the HTML file, you usually need to tell the application the URL of the HTML file you've created. For example, you might enter something like the following into a browser's URL or Location field:

Once you've successfully completed these steps, you should see something like this in the browser window:

Now What?

Now you can:

Previous | Next | Trail Map | Getting Started | Table of Contents