Compiling Applets

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.

Answer:

  • What should the source file be named for this applet? AnotherHello.java
  • What file will be created when the source file is compiled? AnotherHello.class

Compiling Applets

As far as the compiler is concerned, the source file for an applet is just another object definition. It does not matter that the object is an applet. So the compiler works the same as it does with applications. To compile the above applet do this:

C:/> javac AnotherHello.java

This creates AnotherHello.class in your directory.

If you want, you can copy the above source code into an editor, save it to AnotherHello.java, and compile it. You will not be able to run it in the usual way, however.

QUESTION 7:

Why won't

C:/> java AnotherHello

work to run this applet?