0% found this document useful (0 votes)
12 views3 pages

Overview of Java Applet

An applet is a Java program embedded in a webpage that runs on the client side to generate dynamic content. Its life cycle includes methods for initialization, starting, painting, stopping, and destruction, each serving specific purposes in managing the applet's execution. While applets offer advantages like platform independence and client-side functionality, they also face security restrictions and limitations in accessing local resources.

Uploaded by

hegdeg2608
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Overview of Java Applet

An applet is a Java program embedded in a webpage that runs on the client side to generate dynamic content. Its life cycle includes methods for initialization, starting, painting, stopping, and destruction, each serving specific purposes in managing the applet's execution. While applets offer advantages like platform independence and client-side functionality, they also face security restrictions and limitations in accessing local resources.

Uploaded by

hegdeg2608
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Applet:-

Applet is a special type of program that is embedded in the webpage to generate the
dynamic content. It runs inside the browser and works at the client side.

Life cycle of Applet:


1.Initialization

The init( ) method is the first method to be called. This is where you should initialize
variables. This method is called only once during the run time of your applet.

2.Start

The start( ) method is called after init( ). It is also called to restart an applet after it
has been stopped. Note that init( ) is called once i.e. when the first time an applet is
loaded whereas start( ) is called each time an applet’s HTML document is displayed
onscreen. So, if a user leaves a web page and comes back, the applet resumes
execution at start( ).

3.Paint

The paint( ) method is called each time an AWT-based applet’s output must be
redrawn. This situation can occur for several reasons. For example, the window in
which the applet is running may be overwritten by another window and then
uncovered.

4.Stop

The stop( ) method is called when a web browser leaves the HTML document
containing the applet—when it goes to another page, for example. When stop( ) is
called, the applet is probably running. You should use stop( ) to suspend threads that
don’t need to run when the applet is not visible. You can restart them when start( ) is
called if the user returns to the page.

5.Destroy

The destroy( ) method is called when the environment determines that your applet
needs to be removed completely from memory. At this point, you should free up any
resources the applet may be using. The stop( ) method is always called before
destroy( ).


Advantages​
Applets have many advantages over stand-alone applications. Some of them are :

1.​ As applet is a small java program, it is platform independent which is capable


of running in any browser.
2.​ Applets can perform various small tasks on client-side machines. They can
play sounds, show images, get user inputs, get mouse clicks and even get
user keystrokes, etc ...
3.​ Applets creates and edits graphics on the client-side which are different and
independent of the client-side platform.
4.​ As compared to stand-alone application applets are small in size, the
advantage of transferring it over the network makes it more usable.
5.​ Applets run on the client’s browsers , so they provide functionality to import
resources such as images, audio clips based on the URL.
6.​ Applets are quite secure because of their access to resources.
7.​ Applets are secure and safe to use because they cannot perform any
modifications over the local system.
8.​ Various small tasks such as performing login, inventory checking, task
scheduling can be done by applets running over Intranets.



Disadvantages​
Applets have many restrictions over the areas of security because they are obtained
from remote machines and can harm client-side machines. Some of them are as
follows :​

1.​ If we are running an applet from a provider who is not trustworthy then
security is important.
2.​ Applet itself cannot run or modify any application on the local system.
3.​ Applets have no access to client-side resources such as files , OS etc.
4.​ Applets can have special privileges. They have to be tagged as trusted applets
and they must be registered to APS (Applet Security Manager).
5.​ Applet has little restriction when it comes to communication. It can
communicate only with the machine from which it was loaded.
6.​ Applets cannot work with native methods.
7.​ Applet can only extract information about client-machine is its name, java
version, OS, version etc ... .
8.​ Applets tend to be slow on execution because all the classes and resources
which it needs have to be transported over the network.

There are two ways to run an applet

1.​ By html file.


2.​ By appletViewer tool (for testing purpose).

Applet program example


import java.applet.*;
import java.awt.*;

public class HelloWorld extends Applet {


public void paint (Graphics g) {
g.drawString ("Hello World", 100, 100);
}
}

/*

<applet code="HelloWorld.class" width="300" height="300">

</applet>

*/

You might also like