How to write and deploy a Java applet

A Java applet is a special kind of Java program that a web browser enabled with Java can download from the internet and run. An applet is typically embedded inside a web page and runs right in the browser window.

Follow the instructions below to deploy your first applet:


  1. In Eclipse, expand the project folder and package into which your applet should be placed. In the text that follows, this project folder will be named "Paul Oser", and the package will be named "edu.emory.oxford.paul.oser", but your project and package names will likely be different -- just modify things accordingly...

  2. Right-click on the package icon (e.g., "edu.emory.oxford.paul.oser") and select "New->Class". Name the resulting new class "HelloApplet".

  3. Replace the java code found in your HelloApplet class with the code below. Select "Run As->Java Applet" from the Run menu, to verify the applet works. The applet should prompt you to enter your name, and then print a message of the form "Hi ! It is good to meet you!".

    package edu.emory.oxford.paul.oser;
    import acm.program.*;
    public class HelloApplet extends ConsoleProgram {
    	public void run() {
    		println("What is your name? ");
    		String name = readLine();
    		println("Hello " + name + "!  It is good to meet you!");

  4. To deploy an applet, you will need to house it somewhere on the internet. Any easy way to do this is through the use of the free cloud-based storage application "Dropbox". If you don't already have it installed, download and install Dropbox (

  5. Now, in Eclipse, select "File->Export..." and highlight the "JAR file" option found in the "Java" folder shown in the resulting dialog box, and click "Next".

    Select the project folder (e.g., "Paul Oser") in the next dialog box and make sure the corresponding ".classpath" and ".project" options are checked. Make sure "Export generated class files and resources" and "Compress the contents of the JAR file" are checked.

    (Note, these directions will actually export ALL of the classes in your project folder to this jar file -- not just the HelloApplet class. This is fine for now -- but if you wanted to only export some of the classes in your project folder, you could expand the project folder item in this dialog box and navigate to your package (e.g., Paul Oser -> src -> edu.emory.oxford.paul.oser) and then check the classes you want to export when they are displayed on the right.)

  6. Click the "Browse..." button and select a place to save your archive file. Give the archive file an appropriate name (e.g., "paul.oser.jar") and click "Save". Finally, click "Finish" to create the JAR file. You may be notified of some compile warnings when this happens -- you may ignore these.

  7. Open Dropbox, and copy the jar file to the "Public" folder inside your main Dropbox folder. Notice the applet above references the acm.jar library. Since this is not a standard java library, you will also have to copy the acm.jar file to your public folder.

  8. Now right-click your jar file (e.g., "paul.oser.jar") and choose "Dropbox->Copy Public Link".

    Paste this link somewhere (like an empty text file) so that you can inspect it. Note it will take on a form similar to the following: "". The first part of this URL, "", is called the codebase for the applet -- essentially, this tells your browser where your applet's code is located. Copy down the text of your applet's codebase (you will need to refer to it in the next step).

  9. Copy the following into a new text file.

    HelloApplet by Paul Oser
    <h2>HelloApplet by Paul Oser</h2>
    archive="paul.oser.jar, acm.jar" 
    width=550 height=300>

    Replace both occurrences of "Paul Oser" with your name. Then, importantly, modify the line


    to reflect your applet's codebase, and modify the lines

    archive="paul.oser.jar, acm.jar"

    to reflect the names of your jar file(s) and package. Note how the code attribute is specified. Essentially, it is the package name followed by a "/", the class name, and ".class".

    Save the modified text file with a name similar to "paul-oser-hello-applet.html" in the public folder of your main Dropbox folder.

  10. Lastly, right-click the "paul-oser-hello-applet.html" file and select "Dropbox->Copy Public Link". Paste this link into your browser to see your applet in action! Hopefully, it looks something like this page: