The «Hello World» Applet in Java

You have been listening a lot of things about Java for several years, but suddenly you have discovered that not even you know just produce a simple «Hello World». No problem… you are in the good way to become a Java Discover.

In order to implement a «Hello World» applet you need to download the Java 2 Software Development Kit (SDK) from http://java.sun.com/. This kit allows you to compile and debug your Java software.

Follow next steps in order to become a succesfull appleter:

1) Install the Java 2 SDK in your computer (i.e. NT Workstation 4.0).

2) Write a source file in Java named «Hola.java» using the WordPad editor. This file must contain:

import java.awt.*;

public class Hola extends java.applet.Applet {

public void paint(Graphics g) {

g.drawString(«Hello World», 5, 50);

}

}

and must be placed in the ../SDK Directory/bin/ directory where you have installed the SDK.

3) Compile the file through the Java Compiler (javac) using next sentence from ../SDK Directory/bin/ directory in the MS DOS prompt:

javac Hola.java

This action creates an executable file named Hola.class

4) Now, you have to create the HTML page that calls the applet Hola.class. In this way, edit a file called «Test.html» that contains:

<HTML><APPLET CODE=Hola.class></APPLET> </HTML>

5) And it’s all !. Assure that the .HTML and .CLASS files are in the same directory and execute the web page (Test.html) with Netscape Navigator or Internet Explorer.