You are on page 1of 7

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 client side.

Advantage of Applet
There are many advantages of applet. They are as follows:

o It works at client side so less response time.

o Secured

o It can be executed by browsers running under many plateforms, including Linux,


Windows, Mac Os etc.

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

Lifecycle of Java Applet

1. Applet is initialized.

2. Applet is started.

3. Applet is painted.

4. Applet is stopped.

5. Applet is destroyed.

Lifecycle methods for Applet:


The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides 1
life cycle methods for an applet.

java.applet.Applet class
For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle
methods of 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 maximized. 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.

java.awt.Component class
The Component class provides 1 life cycle method of applet.

1. 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.

schematic representation of the methods.

Brief Description of Life Cycle Methods


Following is the brief description of the above methods.

1. init(): The applet's voyage starts here. In this method, the applet object is created by the
browser. Because this method is called before all the other methods, programmer can utilize
this method to instantiate objects, initialize variables, setting background and foreground
colors in GUI etc.; the place of a constructor in an application. It is equivalent to born
state of a thread.
2. start(): In init() method, even through applet object is created, it is in inactive state. An
inactive applet is not eligible for microprocessor time even though the microprocessor is
idle. To make the applet active, the init() method calls start() method. In start() method,
applet becomes active and thereby eligible for processor time.

3. paint(): This method takes a java.awt.Graphics object as parameter. This class includes


many methods of drawing necessary to draw on the applet window. This is the place where
the programmer can write his code of what he expects from applet like animation etc. This is
equivalent to runnable state of thread.

4. stop(): In this method the applet becomes temporarily inactive. An applet can come any
number of times into this method in its life cycle and can go back to the active state (paint()
method) whenever would like. It is the best place to have cleanup code. It is equivalent to
the blocked state of the thread.

5. destroy(): This method is called just before an applet object is garbage collected. This is the
end of the life cycle of applet. It is the best place to have cleanup code. It is equivalent to
the dead state of the thread.

the init() and destroy() methods are called only once in the life cycle. But, start(), paint() and
stop() methods are called a number of times.
Types of drivers in JDBC
JDBC Driver is a software component that enables java application to interact with the
database.Thereare 4 types of JDBC drivers:

1. JDBC-ODBC bridge driver

2. Native-API driver (partially java driver)

3. Network Protocol driver (fully java driver)

4. Thin driver (fully java driver)

1) JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls. This is now discouraged because of thin driver.

Advantages:

o easy to use.

o can be easily connected to any database.

Disadvantages:

o Performance degraded because JDBC method call is converted into the ODBC
function calls.
o The ODBC driver needs to be installed on the client machine.
o
o 2) Native-API driver

The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API. It is not written entirely in java.

Advantage:

o performance upgraded than JDBC-ODBC bridge driver.

Disadvantage:

o The Native driver needs to be installed on the each client machine.

o The Vendor client library needs to be installed on client machine.

3) Network Protocol driver


The Network Protocol driver uses middleware (application server) that converts JDBC calls
directly or indirectly into the vendor-specific database protocol. It is fully written in java
Advantage:

o No client side library is required because of application server that can perform many
tasks like auditing, load balancing, logging etc.

Disadvantages:

o Network support is required on client machine.

o Requires database-specific coding to be done in the middle tier.

o Maintenance of Network Protocol driver becomes costly because it requires database-


specific coding to be done in the middle tier.

4) Thin driver

The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is known as thin driver. It is fully written in Java language.
Advantage:

o Better performance than all other drivers.

o No software is required at client side or server side.

Disadvantage:

o Drivers depends on the Database

You might also like