An applet is a small and portable application that runs under the restricted scope provided by JRE. It has dual compatibility as it can be executed on a web browser and also by applet viewer. JVM is required on the client machine to run an applet program.

Five steps to be kept in mind when writing an applet program:

1. import java.applet.* (Need Applet class from java.applet package)

2. create a public class (Class name and File name must be same in case of public class)

3. extend the class from the base class Applet

4. do not write main method

5. write the applet life cycle methods (i.e.  init, start, stop, destroy, paint)

File name:

import java.applet.*;

public class abc extends Applet

Steps to compile and Run Applet program:

  1. Compile your java code using javac.exe on console/command prompt.
  2. To run the generated class file, we have to write <applet> tag in an additional file(e.g. run.txt). Later on that file name is to be passed as an argument to appletviewer.exe as shown below

File name: run.txt

<applet code="abc" width="500" height="500"></applet>

Commands to be executed: run.txt

c:> javac
c:> appletviewer run.txt