Applet in JAVA

Oct 30 • Notes • 4908 Views • No Comments on Applet in JAVA

An applet is a part of java and as we know that JAVA is a object oriented language which follows the Object Oriented principles i.e; encapsulation, abstraction, inheritance and polymorphism. An as we know that after the creation of C language the problem occurred was of portability on web based programs so JAVA was one of the language which was able to solve this problem. Applet is a kind of small application that is written in JAVA language and are delivered to the users in bytecode form. Here in this post description of Applet in JAVA as a standalone application, as an extension to the other software is given.

Applet as a Standalone Application

When as Applet is hosted by an operating system, it can performed the function of a normal software application with performing only Small sets of tasks. Applications are often classified as applets when accessories are bundled in Microsoft Windows like Windows Notepad or Microsoft Paint. Applets are easily accessible and are not full-featured application programs.

Applet as an Extension for Other Software

In most of the cases, an applet does not run independently. These set of applets either run in a container provided by the host program with the help of a plugin, or a variety of other applications including mobile devices that support the applet programming model.

Applet in JAVA

  • JAVA can also be used for the development of web based application so applet can be used as a tool for the development of the web based application in JAVA. Therefore Applet can be defined as a JAVA program that runs on the web browser of the client.
  • In other words applets can also be defined as a java class that extends the JAVA. Applet class but difference between a simple JAVA Class and Applet class is that in Applet Class there is no main() method that is an applet class does not define a main method.
  • as applets used for web browsers so applets are designed to be embedded in a HTML page.
  • So when a HTML page is opened than the code for the Applet is downloaded on the users machine but to read this code or to understand the code for the applet we require JVM. A JVM is a JAVA Virtual Machine used as an interpreter to read the java byte code. So, this JVM can be provided as a plugin  by the browser or the system have the run time environment to run that applet code. so we can say that the purpose of JVM (JAVA Version Machine) is to create instance of the Applet Class and to invoke various method during the Applet life time.

Applet Life Time

When an Applet is loaded, then it go for continuous series changes in its state. An Applet states include four states namely,  Born or initialization state, Running state, Idle state and the last one is destroyed state . Following are the changes in various state of Applet Life Cycle is shown in following figure

Applet Life Cycle Diagram

Applet Life Cycle

  • init: The purpose of this method is to find the initialization needed for the applet
  • start: This method invokes when init is called that is when the browser calls the init method.
  • stop: This method is invoked when the user changes the web page.
  • destroy: This method is always called when the browser shut downs automatically.

Hope this post will give you a general description about applet.

Following  is the example of small applet program

public class MyApplet extends Applet
public void paint(Graphics g)
g.drawString(“Hello world”, 25,50)

Find Core JAVA Notes including Applet in JAVA in pdf

Related Links:

Reader can give their suggestion by using comment section given below the post..!! 

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published.

« »