Environment Setup
Before you can compile and actually run any applet in this track, you need one specific tool that
modern JDK installations no longer ship with: appletviewer. This lesson walks through why
that matters, what to install, and how to compile and run an applet from the command line.
appletviewer
command-line tool used to test an applet without a real browser was itself removed in
JDK 11. To actually compile and run the applet code in this track, you need
JDK 8 installed - the last major release with full, unimpeded applet and
appletviewer support. Keep your modern JDK (17, 21, or whatever you use day to day) for
everything else; just add JDK 8 alongside it for this track specifically.
Installing JDK 8 Alongside a Modern JDK
You do not need to uninstall or replace whatever JDK you already use. The cleanest approach is to
install JDK 8 into its own separate folder and point your terminal at it only when you're working
through this track, using its full path or by temporarily changing your PATH/
JAVA_HOME in that terminal session.
- Download a JDK 8 build. Oracle's own JDK 8 requires an Oracle account for newer updates, so most learners use a free OpenJDK 8 distribution instead - Eclipse Temurin (Adoptium), Amazon Corretto 8, or Azul Zulu 8 all work identically for this track.
- Install it to a dedicated folder rather than letting it overwrite your default JDK - for example
C:\Java\jdk8on Windows or/opt/jdk8on Linux/macOS. - Verify the install by calling
javaandjavacwith their full path, for exampleC:\Java\jdk8\bin\java -version, and confirm it reports a1.8.0_xxxversion string. - Optionally, set a
JAVA8_HOMEenvironment variable pointing at the JDK 8 folder, so you can reference%JAVA8_HOME%\bin\javac(Windows) or$JAVA8_HOME/bin/javac(macOS/Linux) without retyping the full path every time.
PATH or default JAVA_HOME at all.
Calling the JDK 8 binaries by their full path in a terminal keeps this tutorial's toolchain completely
isolated from the rest of your Java work.
Compiling an Applet
Compilation itself is nothing special - it's the same javac command you already know,
just invoked with your JDK 8 compiler. Given a source file named PaintApplet.java:
# from the folder containing PaintApplet.java
javac PaintApplet.java
This produces a PaintApplet.class file in the same folder, exactly as it would for any
other Java class. Applets are not compiled any differently from standalone applications - the
difference only shows up in how the resulting class is run.
Running an Applet with appletviewer
Since no browser can load an applet, appletviewer exists as a lightweight standalone tool
that reads an HTML file, finds an <applet> tag inside it, and opens a small window
that behaves like a browser's applet viewport - without needing an actual browser or plugin. You'll
meet the full <applet> tag syntax in Embedding
in HTML; for now, here's the minimal HTML file appletviewer needs:
<html>
<body>
<applet code="PaintApplet.class" width="400" height="300"></applet>
</body>
</html>
Save that as index.html in the same folder as PaintApplet.class, then run:
# from the folder containing both files
appletviewer index.html
A small window opens hosting your applet, and appletviewer drives its lifecycle
(init, start, paint, and so on) exactly the way an old browser
plugin would have.
What About My IDE?
Modern versions of IntelliJ IDEA and Eclipse have progressively dropped built-in "Run as Applet"
configurations as the API faded out of relevance, and some no longer offer one at all. Rather than
fighting an IDE's plugin ecosystem to resurrect applet support, the most reliable and least
frustrating way to follow this track is the plain command line with JDK 8's javac and
appletviewer, as shown above. You can still write and edit the .java files in
whatever editor or IDE you like - you're only bypassing the IDE for the compile-and-run step.
| Task | Command |
|---|---|
| Check JDK 8 is available | java -version (using the JDK 8 binary's full path) |
| Compile an applet | javac PaintApplet.java |
| Run it in a viewer | appletviewer index.html |
appletviewer was removed in
JDK 11. Compiling an applet uses ordinary javac; running one requires
appletviewer pointed at an HTML file with an <applet> tag, since no
browser can do this anymore.
appletviewer ready, move on to
The Applet Lifecycle to understand exactly which methods
appletviewer calls, and when.