Chapter 7. Java™ Applets - An Introduction

Table of Contents

Introduction
A Simple Applet Example - Hello World!
The Life Cycle of an Applet
Hello World Applet - In Detail
ChessApplet - An Applet for you to try!
Passing Parameters To An Applet
An Exercise For You! Passing parameters to an Applet.

Introduction

A Java applet is a special kind of Java application that is designed to work within a web browser. Java Applets (Java Home Page. ) are special in that they can only use a subset of the total functionality of the Java Virtual Machine. This is for several reasons:

  • Java applets are usually compact[11] , so that they can be easily downloaded across the web.

  • Applets are not permitted to perform file or certain memory operations on the client machine, which prevents hostile applets from attacking a client machine, for example, trying to delete files on the machine or locking out resources.

  • Applets have no main() method. Instead they have a set of methods that will be called in a particular order.

Packaged with the Java Software Development Kit (Java JDK 6) is an appletviewer. The appletviewer is the minimum requirement for a web-browser, that allows applets to run without having to use a full web browser. When calling the appletviewer you must pass the name of a HTML file that contains the <APPLET> tag, an extension to the HTML language. This <APPLET> tag specifies the name of the initial Java class to load and the initial width and height of the applet.



[11] Usually in the range of 4KB to 10KB