You are on page 1of 12

APPLET

 An applet is a Java program that runs in a Web browser.


 It runs inside the browser and works at client side.
 It works at client side so less response time.
Applets are client side means they execute in your browser. When you open a webpage or an url
containing applet it fetches the applet from server but it does not executes on server, it executes in your
browser.
 Applets are used to make the web site more dynamic and entertaining.
 A main() method is not invoked on an applet,and an applet class will not define main().
Applets fall under partial web based program. There is no main(), as it does not require the same.We use AppletViewer
instead of the main() where the applet file is embeded in the html file.
 An applet is a Java class that extends the java.applet.Applet class.
 A JVM is required to view an applet.

LIFE CYCLE OF AN APPLET


1. public void init(): is used to initialized the Applet. It is invoked only once.

2. public void start(): is invoked after the init() method or browser is maximised.
It is used to start the Applet.

3. public void stop(): is used to stop the Applet. It is invoked when Applet is stop
or browser is minimized.

4. public void destroy(): is used to destroy the Applet. It is invoked only once.

5. public void paint(Graphics g): is used to paint the Applet. It provides Graphics
class object that can be used for drawing oval, rectangle, arc etc.
• Who is responsible to manage the life cycle of an applet?
Java Plug-in software. The Java plugin is part of the Java Runtime Environment (JRE) and allows a
browser to work with the Java platform to run Java applets to execute in the browser. The Java Plugin is a
special way to run Applets.
All applets are sub-classes (either directly or indirectly)
of java.applet.Applet class.

• Running of applet programs


Applet program can run in two ways.
1.Using html (in the web browser)
2.Using appletviewer tool (in applet window)
Advantage of Applet
• There are many advantages of applet. They are as follows:
• It works at client side so less response time.
• Secured
• It can be executed by browsers running under many plateforms, including
Linux, Windows, Mac Os etc.

Drawback of Applet
• Plugin is required at client browser to execute applet.
PACKAGES

A package provides a mechanism for grouping a variety of similar types of


classes, interfaces and sub-packages.
Benefits
 The classes contained in the packages of other programs can be reused.
 In packages, classes can be unique compared with classes in other packages.
 Packages provides a way to hide classes.
Type of package
Package are classified into two type which are given below.
1. Predefined or built-in package.
2. User defined package.
Predefined or built-in package
• These are the package which are already designed by the Sun Microsystem and supply
as a part of java API, every predefined package is collection of predefined classes,
interfaces and sub-package.

User defined package


• If any package is design by the user is known as user defined package. User defined
package are those which are developed by java programmer and supply as a part of
their project to deal with common requirement.
Java API packages:
Java.lang – contains classes for primitive types, strings, math functions,
threads and exception.
Java.util – contains classes such as vectors, hash tables , date etc.
Java.io – stream classes for I/o.
Java.awt – classes for implementing GUI – windows ,buttons , menus etc.
Java.net – classes for networking.
Java.applet – classes for creating and implementing applets.

Packages name are dot separated, e.g., java.lang.


Accessing classes in a package
import packagename.classname;

Example: import java.awt.color;


import java.applet.*;
import java.awt.*;
public void paint (Graphics g)
{
g.drawString (“java", 25, 50);
}

You might also like