You are on page 1of 17

BCA-503

Assignmet-2
Advanced Java

Q=1: Explain the RIM architecture and the method of its


working.
Ans =1
RIM architecture
Bgbg
gb CLIENT
Client
Application

Stub

TCP/IP

SERVER

-------------------------------------------------------

Remote
reference

Skeleton

----------------------------TCP/IP

Physical Network

1. Client Application:
This is the application running on the client system.
The client obtains a reference to the remote server.
Once reference is obtained, a method can be invoked on the remote
reference.

2. Stub:

The Stub is a server-side proxy on the client.


It represents the server on the client side.
Any remote call is passed onto the Stub.
The stub marshals the method call.
Marshalling is the process of converting data into a network-ready form.
Marshalling is nothing but encoding and serialization of data.

3. TCP/IP and physical network:

RIM runs over the TCP/IP protocol.

4. Skeleton:
The skeleton is the client-side proxy on the server side.
It receives network data from the Stub.
It then un-Marshalls the data.
Un-Marshalling is the reverse process of marshalling.
The Stub once again Un-Marshalls it and return the result to the client
application.

Method of its working


The working of RIM is given below:
1. Create a server application.
2. Register the server instance with a registry/directory service using an alias
name.
3. Create the client application.
4. The client application looks-up the registry using the alias name
5. The client obtains the remote server instance.
6. The client invoked methods on the instance.
7. Server processes requests and sends back results to the client.

Program to display a message through RIM


Hello.java
Package
Import java.rmi.*;
Import java.rmi.server.*;
Import java.rmi.server.unicastRemoteObject*;
Public class hello extends unicastRemoteObject implements hello interface
{
Private string message;
Public hello (String Msg) through Remote Exception
{
Meassage=Msg
}

Public string say () throws Remote Exception


{
Return message;
}
}

Helloclient.java
Package
Import java.rmi.Naming;
Public class helloclient
{
Public static void main (String args [])
{
Try
{
HelloInterface
Hello= (Hello Interface) naming. Lookup (//local host/hello) ;
System.out.println (hello.say ());
}
Catch (Exception e)
{
System.out.println (helloclient exception:+e);
}

}
}

helloInterface.java
Package
Import java, rmi.*;
Public interface helloinetrface extends Remote
{
Public string say () throws RemoteException
}

Helloserver.java
Package
Import java.rmi.Naming;
Import java.rmi.registry.Registry;
Public class helloserver
{
Public static void main (String args [])
{
Try
{
Registry r= java.rmi.registry.LocateRegistry.CreateRegistry (1099);

R. rebinds (hello, new hello (Arsenal Football Club, THFC forever


in our Shadow,);
}
Catch (Exception e)
{
System.out.println (server not connected:+e);
}
}
}

OUTPUT
Server is connected and ready for operation
Arsenal Football Club, THFC forever in our Shadow.

Q=2: write Short notes on:


a) Advanced RMI concepts
RMI uses the JRMP-java Remote method protocol to communication
It works on TCP/IP.

Role of the Registry

The registry hosts the remote reference using an alias name.


The registry is itself a remote application.
By default, the registry runs on port 1099.
The registry maintains a hash Table.
It provides a solution for bootstrapping problem.

Changing the default port where RMI Registry is running


In the server application, create a new registry and bind the remote
reference to the registry created by your program
E.g.:
Arithlmpl server = new arithlmpl ();
Registry reg =LocateRegistry.createRegistry (5000);
Reg.rebind (arith, server);
In the client application, lookup for the remote reference on the port
of your registry.
E.g.:
Arithnt server=(arithlnt)naming.Lookup(rmi://10.1.1.10:5000/arith);
(It is assumed that the server application is on the system with ip
address10.1.1.10)

b) Troubleshooting

If path is not set properly, i.e. java<java source file> say bad command or file
name
Go to Start->Setting->Control panel->system.
Go to Advanced tab and choose environment variables.
In the system variables or use variables section, choose path and
click Edit.
If path is not available, click on new and type path in the
variables name field.
E.g.:
Choose ok three times and close all windows
Close all command prompts and start them again
If any of to the application does not run properly, set the class path.

Go to your folder, type set class path =5 class path%;


Repeat it for all command prompts you open.
Class path can also be set in the Environment variables.
In this create a new environment variable named class path and give
its value as the path of your directory.
In the client program.
In the main method. Type the following line
System.setSecurityanager (New RMISecurityManager () );
This will set a security manager for your client application.

c) JavaBeans

The JavaBeans APL makes it possible to write component software in


the java programming language.
Components are self-contained, reusable software units that can be
visually composed into composite components, applets, application
and servlets using visual application builder tools.
JavaBeans component are known as Beans.
Components expose their features to builder tools, for visual
manipulation.
A Beans features are exposed because feature names adhere to
specific design patterns.
A JavaBeans-enabled builder tools can then examine the Beans
patterns, decide its features, and expose those features for visual
manipulation.
A builder tool maintains Beans in a palette or toolbox.

Beans support introspection class relies in two ways:


1. By adhering to specific rules, known as design patterns, when naming
Bean feature:
The java.beans.introspector class examines Beans for these design
patterns to discover Bean features.
The introspect or class relies on the core reflection API
2. By explicitly providing property, method and event information with a
related Bean information class:
A Bean information class implements the Bean info interface.
A bean info class explicitly lists those Bean features that are to be
exposed to application builder tools.

Java Bean Feature

Properties: These are a Beans appearance and behavior


characteristics that van be changed at design time.
Events: Bean use events to communicate with other Beans.
Builder tools can examine a Bean and determine which
events that Bean can fire and which it can handle.
Persistence: enable Beans to save and restore their state.
JavaBeans uses java Object Serialization to support
Persistence.
Methods: A Beans methods are on different from java
methods, and can be called from other Bean or a scripting
environment.

d) JNDI
A Naming service is analogous to a telephone operator.
When you want to call up someone over the phone and you do not
know the persons phone number.

A naming service is an entity that performs the following tasks:


It associates names with object. We call this as binding names to
object.
It provides a facility to find as object based on a name. We call this
lookup or searching for as object.
Naming services are everywhere in computing.
When you want to locate machine on the network, the Domain Name
System (DNS) is issued to translate machine name to an IP address.
If you lookup IKC.COM on the internet, the name IKC.COM is
translated into the IP address of this site.
But one type of object is important, namely a directory objects.
A directory object is different from a generic object because you can
store attributes with directory object.
These attributes can be used for a wide variety of purposes.

Metadata
Directory metadata defines the structure of your directory.
It defines the schema of how your directory is laid out.
Metadata supplies a set of rules about your directory, such as
restriction on tree branches, restrict on attributes, and more.
Overall, directories are not very different from databases.
You can think of a directory as a scaled-down, simplified database.

Problems with naming and directories


There are many popular naming and directory products out today.
Directory vendor differentiate product line by offering different types
of service.
Unfortunately, this leads to different naming and directory standards.

And each directory standard has a different protocol for accessing the
directory.
It also means you need to download a new library, learn a new API,
and test new code each time you use a different directory.

Person 1
People
Person 2
Printer 1
My
Company

Printers

Computer 1
Network
services

Computers

Fax
Machines

Computer 2

e) Servlets
Fax

Servlets are modules that extend request/response-oriented


Machinesservers,
such as java-enabled web servers.
For example, a servlest might be responsible for taking data in an
HTML Oder-entry form and applying the business logic used to
update a companys order database.

Servlets are to server what applets are to browsers.


Unlike applets, however, servlets have no graphical user interface.
Servlets have become most widely used within HTTP servers
because many web servers support the servlets API

Other user of servlets

Here are a few more of the many application for servlets:


Allowing collaboration between people: A servlets can synchronize
request. This allows servlets to support system such as on-line
conferencing.
Forwarding requests: Servlets can forward requests to other servers and
servlets. Thus, servlets can be used to balance load among several
servers that mirror the same content, and to partition a single logical
service over several servers, according to task type or organizational
boundaries.

Architecture of the servlets package


The javax.servlets package provides interface and classes for writing
servlets.
The architecture of the package is described below.

The servlets interface


The central abstraction in the servlets API is the servlets interface.
All servlets implement this interface, directory or, more commonly, by
extending a class that implements it such as httpServlet.

Servlets

Generic
Servlet
Http Servlet

My Servlet

The servlet interface declares, but does not implement that manage the
servlet and its communication with client.
Servlet writers provide some or all of these methods when developing
a srevlet.

You might also like