Applet in Java

Applet is a Java program designed for execution within the web browser. They are embedded into HTML pages and run on Java enabled web browsers like Mozilla Firefox and Internet Explorer. An applet is a Java subclass that extends the java.applet.Applet class. Applets are also useful for a small Internet and intranet applications. They run remotely on the client browser and cannot access system resources on the local computer. They make a website more dynamic.

Applet in Java

Applet is a Java program designed for execution within the web browser. They are embedded into HTML pages and run on Java enabled web browsers like Mozilla Firefox and Internet Explorer. An applet is a Java subclass that extends the java.applet.Applet class. Applets are also useful for a small Internet and intranet applications. They run remotely on the client browser and cannot access system resources on the local computer. They make a website more dynamic.

Applet in Java


Applet is a Java program designed for execution within the web browser. They are embedded into HTML pages and run on Java enabled web browsers like Mozilla Firefox and Internet Explorer. These web browsers download Applet from the Internet and run them.

An Applet is a Java subclass that extends the java.applet.Applet class

Applets are also useful for a small Internet and intranet applications. They run remotely on the client browser and cannot access system resources on the local computer. They make a website more dynamic.

An <applet> tag is used to embedding an applet in an HTML file and the file are viewed through Java-enabled web browsers.

Advantages of Applet:

  • Applets can run on Windows, Linux and Mac OS
  • Applets are secure
  • Almost all web browsers support Applets
  • Applets work on all Java plug-ins version
  • Applets can work without security approval
  • Applets are quickly loaded as they are cached in web browsers

Disadvantages of Java Applet:

  • To run an Applet Java plug-ins are necessary
  • Java applet requires JVM
  • Though in most of the web browsers Applets are cached but if they are not they are downloaded from internet and it takes time

Life Cycle of an Applet:

init():

init() method takes place whenever a page with Applet is loaded and initializes everything that is needed to be initialized for an applet. init() method is called only once and after the param tags have been processed.

start():

start() method is automatically called after init() method. It is also called whenever user leaves a web page and comes back to the page containing the applet.

stop():

stop() method is automatically called when the user goes off to other page than the page in which the applet sits.

destroy():

destroy() method is only called when the browser shuts down normally.

Example of Applet in Java:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class HelloWorldApplet extends Applet{
  public static void main(String[] args){
  Frame frame = new Frame("Roseindia.net");
  frame.setSize(400,200);
  Applet app = new HelloWorldApplet();
  frame.add(app);
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  System.exit(0);
  }
  });
  }
  public void paint(Graphics g){
  g.drawString("Hello World!",200,100);
  }
}