Experiment:-1 Objective:-Introduction To Component. What Is Components?
Experiment:-1 Objective:-Introduction To Component. What Is Components?
Experiment:-1
Objective:-Introduction to Component.
What is Components?
A component is a modular, portable, replaceable, and reusable set of well-defined
functionality that encapsulates its implementation and exporting it as a higher-level interface.
Component technology refers to the use of software components for software development.
Software components usually confirm to a component model, and they are often hosted and
managed by a component framework, which provides a controlled environment where
components can be composed together to form larger applications or systems.
Component is a functionality independent path of system. It performs some function and they
required some input or produce output.
Encapsulated − A component depicts the interfaces, which allow the caller to use its
functionality, and do not expose details of the internal processes or any internal
variables or state.
Features of Components:-
Benefits of Components:-
A component is more generalized and application-independent.
Components can be reused in a variety of contexts.
Individual components can be custom-made to suit specific requirements, whereas
existing ones can be customized to meet those requirements.
Several components can be assembled to form a functioning system.
Upgrades of individual components end the problem of massive upgrades as done in
monolithic systems.
Components can live anywhere on a network - in computers best suited for running
them - based on the functions the components provide.
Using distributed computing system standards such as CORBA, Java RMI and EJB,
and Microsoft's COM/DCOM, components can be distributed among the computers
in an enterprise network.
Pradyumna Mittal 16010BTIT00609
Experiment:-2
What is jdbc?
Java Database Connectivity(JDBC) is an Application Programming Interface(API) used to
connect Java application with Database. JDBC is used to interact with various type of
Database such as Oracle, MS Access, My SQL and SQL Server. JDBC can also be defined as
the platform-independent interface between a relational database and Java programming.
JDBC is alsoused for database-independent connectivity between the Java programming
language and a wide range of databases.
The JDBC library includes APIs for each of the tasks mentioned below that are commonly
associated with database usage.
Fundamentally, JDBC is a specification that provides a complete set of interfaces that allows
for portable access to an underlying database. Java can be used to write different types of
executables, such as −
Java Applications
Java Applets
Java Servlets
Java ServerPages (JSPs)
Enterprise JavaBeans (EJBs).
All of these different executables are able to use a JDBC driver to access a database, and take
advantage of the stored data.
JDBC Architecture:-The JDBC API supports both two-tier and three-tier processing
models for database access but in general, JDBC Architecture consists of two layers −
The JDBC API uses a driver manager and database-specific drivers to provide transparent
connectivity to heterogeneous databases.
Pradyumna Mittal 16010BTIT00609
The JDBC driver manager ensures that the correct driver is used to access each data source.
The driver manager is capable of supporting multiple concurrent drivers connected to
multiple heterogeneous databases.
Following is the architectural diagram, which shows the location of the driver manager with
respect to the JDBC drivers and the Java application –
2. JDBC API Driver:-In a Type 2 driver, JDBC API calls are converted into
native C/C++ API calls, which are unique to the database. These drivers are typically
provided by the database vendors and used in the same manner as the JDBC-ODBC
Bridge. The vendor-specific driver must be installed on each client machine.
If we change the Database, we have to change the native API, as it is specific to a
database and they are mostly obsolete now, but you may realize some speed increase
with a Type 2 driver, because it eliminates ODBC's overhead.
Your application server might use a Type 1, 2, or 4 driver to communicate with the
database, understanding the nuances will prove helpful.
Pradyumna Mittal 16010BTIT00609
This kind of driver is extremely flexible, you don't need to install special software on
the client or server. Further, these drivers can be downloaded dynamically.
Uses of JDBC:-
If you are accessing one type of database, such as Oracle, Sybase, or IBM,
the preferred driver type is 4.
If your Java application is accessing multiple types of databases at the same time,
type 3 is the preferred driver.
Type 2 drivers are useful in situations, where a type 3 or type 4 driver is not
available yet for your database.
The type 1 driver is not considered a deployment-level driver, and is typically
used for development and testing purposes only.
1. Driver class: The driver class for the mysql database is com.mysql.jdbc.Driver.
2. Connection URL: The connection URL for the mysql database is
jdbc:mysql://localhost:3306/db1 where jdbc is the API, mysql is the database,
localhost is the server name on which mysql is running, we may also use IP address,
3306 is the port number and db1 is the database name. We may use any database, in
such case, we need to replace the sonoo with our database name.
3. Username: The default username for the mysql database is root.
Pradyumna Mittal 16010BTIT00609
4. Password: It is the password given by the user at the time of installing the
mysql database. In this example, we are going to use root as the password.
System.out.println(rs.getString(1)+"\t\t"+rs.getString(2)+"\t\t"+rs.getString(3)
+"\t\t"+rs.getString(4));
}
}
catch(Exception e)
{
Pradyumna Mittal 16010BTIT00609
System.out.println(e);
}
}
}
Output:-
Pradyumna Mittal 16010BTIT00609
Experiment:-3
Objective:- Introduction to RMI and its implementation.
Introduction:-
The RMI (Remote Method Invocation) is an API that provides a mechanism to create
distributed application in java. The RMI allows an object to invoke methods on an object
running in another JVM.
The RMI provides remote communication between the applications using two objects stub
and skeleton.
Goals of RMI:-
Following are the goals of RMI −
RMI Architecture:-
In an RMI application, we write two programs, a server program (resides on the server) and
a client program (resides on the client).
• Inside the server program, a remote object is created and reference of that object is
made available for the client (using the registry).
• The client program requests the remote objects on the server and tries to invoke its
methods.
The following diagram shows the architecture of an RMI application.
Pradyumna Mittal 16010BTIT00609
Stub:-
The stub is an object, acts as a gateway for the client side. All the outgoing requests are
routed through it. It resides at the client side and represents the remote object. When the
caller invokes method on the stub object, it does the following tasks:
1. It initiates a connection with remote Virtual Machine (JVM).
2. It writes and transmits (marshals) the parameters to the remote Virtual Machine (JVM).
3. It waits for the result.
4. It reads (unmarshalls) the return value or exception.
5. It finally, returns the value to the caller.
Skeleton:-
The skeleton is an object, acts as a gateway for the server side object. All the incoming
requests are routed through it. When the skeleton receives the incoming request, it does the
following tasks:
1. It reads the parameter for the remote method.
2. It invokes the method on the actual remote object.
3. It writes and transmits (marshals) the result to the caller.
Steps of implementations:-
1. create the remote interface:- For creating the remote interface, extend the
Remote interface and declare the RemoteException with all the methods of the remote
interface. Here, we are creating a remote interface that extends the Remote interface.
There is only one method named add() and it declares RemoteException.
import java.rmi.*;
public interface Adder extends Remote
{
public int add(int x,int y)throws RemoteException;
}
In case, you extend the UnicastRemoteObject class, you must define a constructor that
declares RemoteException.
import java.rmi.*;
import java.rmi.server.*;
Pradyumna Mittal 16010BTIT00609
3. create the stub and skeleton objects using the rmic tool:-Next step is
to create stub and skeleton objects using the rmi compiler. The rmic tool invokes the
RMI compiler and creates stub and skeleton objects.
mic AdderRemote
4. Start the registry service by the rmiregistry tool:-Now start the registry
service by using the rmiregistry tool. If you don't specify the port number, it uses a
default port number. In this example, we are using the port number 5000.
rmiregistry 5000
Output:-
5. Create and run Server Application:- In this example, we are binding the
remote object by the name sonoo.
Pradyumna Mittal 16010BTIT00609
import java.rmi.*;
import java.rmi.registry.*;
public class MyServer
{
public static void main(String args[])
{
try
{
Output:-
6. Create and run Client Application:- At the client we are getting the stub
object by the lookup() method of the Naming class and invoking the method on this
object. In this example, we are running the server and client applications, in the same
machine so we are using localhost. If you want to access the remote object from
another machine, change the localhost to the host name (or IP address) where the
remote object is located.
import java.rmi.*;
Pradyumna Mittal 16010BTIT00609
Output:-