
CHAPTER 7
Applets
An applet, as the name implies, is a kind of mini-application, designed to be
downloaded over a network from a possibly untrusted source and run in a web
br owser or in the context of some other applet viewer application. Because of the
ubiquity of web browsers, applets are a useful and powerful way of delivering
Java programs to end users. In fact, it was the power of applets that popularized
Java in the first place. Applets differ from regular applications in several important
ways:
•Anapplet doesn’t have a
main() method like a standalone Java application
does. Writing an applet is a lot more like subclassing an AWT or Swing com-
ponent than writing a standalone application.
•Anapplet is not invoked using the command line, as a Java application is.
Instead, an applet is embedded within an HTML file with an
<APPLET> tag.
And, instead of reading command-line arguments as an application does, an
applet gets its arguments from
<PARAM> tags in the HTML file.
•Anapplet is usually subject to a number of strict security restrictions that pre-
vent untrusted, and possibly malicious, applet code from damaging the host
system.
This chapter briefly explains how applets are written and how they are embedded
in HTML pages. It also explains the security restrictions to which applets are
subject.
Wr iting Applets
Fr om a programmer’s standpoint, one of the biggest differ ences between an applet
and an application ...