677
Summary
A Java application must have a method named main, and the included classes should
all have constructors. A Java applet, on the other hand, is a class derived from the
class Appletthat implements ActionListener; here, the class is its own listener, and
initializations are done within the initmethod. Most applets are in event loops that
continue running until the applet window is closed or you exit the Web page within
which the applet is embedded.
The link to the Bytecode version of the applet is found within a Web page. An exam-
ple of HTML code that provides the link is <APPLET code = "FactInt.class" width=250
height=150>. Using the keyword codefollowed by the equals sign and a file
name with a .classextension says to execute the Bytecode stored in that file.
Quick Check
1.How do applications and applets differ in terms of how they are used?
(pp. 660–661)
2.How does a Web page get loaded into your browser? (pp. 667–668)
3.What is HTML used for? (pp. 668–669)
4.In an applet class heading, what phrase must follow the applet class name?
(pp. 661–667)
5.How is an applet linked within a Web page? (pp. 668–669)
6.What is the meaning of the .classextension? (p. 667)
Answers
1.An application is a stand-alone program that solves a problem. An applet is a small piece of code that
runs under a browser.
2.When you enter a URL into your browser, the browser goes to that place and brings back a copy of what is
there for you to see, including any applets to which it links.
3.HTML is the language used to write Web pages.
4.extendsAppletimplementsActionListener
5 .<APPLET code = "AppletName.class" ... >links the applet whose Bytecode is stored in the file
AppletName.classinto the Web page.
6..classmeans that the file contains the Bytecode version of an applet.
Exam Preparation Exercises
1.Name four ways in which applets differ from applications.
2.Because applets do not have constructors, where are their initializations
carried out?