Kunal Java Unit-4&5
Kunal Java Unit-4&5
Kunal Java Unit-4&5
application.
init(): Called once when the applet is first loaded. Used for initialization.
public void init() {
// Initialization code
setBackground(Color.white);
}
start(): Called each time the applet becomes active (e.g., when the user revisits
the web page).
public void start() {
// Code to start or resume execution
thread = new Thread(this);
thread.start();
}
paint(Graphics g): Called whenever the applet needs to be redrawn. This is
where the applet’s UI is defined.
public void paint(Graphics g) {
// Drawing code
g.drawString("Hello, Applet!", 50, 25);
}
stop(): Called when the applet is no longer active (e.g., when the user leaves the
web page).
public void stop() {
// Code to suspend execution
thread = null;
}
destroy(): Called once when the applet is being unloaded from memory.
public void destroy() {
// Cleanup code
// No need to nullify thread since it's already stopped
}
2. What is JDBC? Explain its types.
JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and
execute the query with the database. It is a part of JavaSE (Java Standard Edition).
JDBC API uses JDBC drivers to connect with the database. There are four types of
JDBC drivers:
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.
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. Th
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 depend on the Database.
3. What is RMI? Write different steps to create RMI application.
ANS- Remote Method Invocation (RMI) is a Java API that enables an object running
in one Java Virtual Machine (JVM) to invoke methods on an object running in
another JVM. This allows for distributed computing, where different parts of an
application can run on different machines.
Steps to Create an RMI Application
Create a Remote Interface:
import java.rmi.*;
} catch (Exception e) {
System.out.println("Server exception: " + e);
}
}
}
Create the Client:
import java.rmi.*;
import java.rmi.registry.*;