Skip to main content


Java technologies allow building the distributed applications.  Application that has been distributed on different machines in the form of executable pieces is called distributed. All the executable pieces work as one application that is transparent for external user. It means external user does not fell that application on which he/she is working is not on the system on which he/she is working.


Java provides a feature that enables developer to develop the distributed application in the form of objects those are distributed on the different machines and this is accomplished by the RMI. RMI stands for Remote Method Invocation. RMI allows invoking the method of an object that is located on the remote JVM in the current object of program. That RMI provides the facility of object-to object communication.

Object may be located on the different machine or in the single machine but the JVM in which they are executing will deferent. There is remote interface that contains declarations of the methods of remote object and to call these methods client object uses this interface to declare the remote interface type reference variable to hold the object reference of the remote object.

RMI application is the combination of two different applications. One application is known as server and second is the client application.  Both applications run on the deferent Virtual machines.

Scenario of working is very simple.

       A server program runs on its machine and creates some remote objects. 
       Server makes the references of these objects to access remotely.
       After this, server waits for client to invoke methods on these objects.
       Client program obtains a reference of a remote object reside of the server.
       And then invokes the method of that object.

Remote object is the object that implements the Remote interface directly or indirectly. The object that implements the remote interface will have following characteristics:

A remote interface extends the interface java.rmi.Remote
Each method of the interface throws java.rmi.RemoteException ,.

 When this object is used by the client, original copy of this object is not passed for client java virtual machine. RMI passes a remote stub for the remote object. The stub acts as the local representative or a proxy for the remote object and client use it for the remote reference. The client invokes the method on the stub object, which is responsible to deliver the task for remote object.

            A stub for the remote object has the same behavior that is it implements same interfaces that the remote object implements.  Only those method defined by the remote interface are available to be called from the client Java virtual Machine.

Logical Architecture

Here stub and Skelton are two objects that work for intercepting the calls made by the client application object and the result returned by the remote objects.  It transfers the data to the remote reference by marshaling and receives data from remote reference by demarshaling. Marshaling convert the data or object being transfer into byte stream and demarshaling refers to converting byte stream into data or into object.

Remote reference layer is used to manage the reference to remote object. It connects client to remote object use the reference containing by it. Client side the remote reference is received by the lookup method and it is hold by the reference variable type of remote interface.

Locating the remote object

Java provides the RMI naming service that is used to store the entry of the references of remote objects having the name through which they will be identified across the different Java virtual machines. It contains the hash table having the key value for each object. Client use particular key value to get the reference for specified object. RMI has the implementation of the interface java.rmi.registry.Registry that is the naming class. The rmi registry runs on the machine and accepts queries from the client on the port by default 1099.

There is a method of class Naming i.e. lookup. Lookup method is used to locate the object reference of the specified name. It accepts an argument having the full information of the remote object host and the remote object. It has contains
The host name of the remote object, Port address of the remote application and Name of the object entry into registry as shown below.

Client invokes the method lookup that takes the complete name of the remote object including the host name and port address on which located it. Then rmiregistry is used to find the object reference.

If name found into the rmi registry, the reference value associated by that name is returned. Client store this reference into the reference variable and later use it to invoke the method on the remote object.

To set the reference into the rmiregistry, bind or rebind methods of class Naming are used to bind the object reference to particular name.
Example 1
Example 2


Popular posts from this blog

Using HyperSQL (HSQLDB)

HSQLDB is a portable RDBMS implemented in pure java. It can be embedded with your application as well as can be used separately. It is very a small database that supports almost all features of the standard database system. It comes with small jar file that can be found in lib folder. The HSQLDB jar package is located in the /lib directory of the ZIP package and contains several components and programs. Core components of jar file are : HyperSQL RDBMS Engine (HSQLDB), HyperSQL JDBC Driver, Database Manager, and Sql Tool. Installing and Using Download: download latest release of HyperSQL database from website and extract it. You will see following contents. Here "bin" directory contains some batch files those can be used to run a swing based GUI tool. You can use runManagerSwing.bat to connect to database, but database must be on before running it. Directory lib contains File hsqldb.jar . It is the database to be used by you. Running database First

How to handle values from dynamically generated elements in web page using struts2

Some time you will see the form containing the button " Add More " . This facility is provided for the user to get the values for unknown number of repeating for some information. for example when you are asking to get the projects details from user, you need to put the option to add the more project for the user since you don't known how many projects user have. In the HTML form, you repeat the particular section to get the multiple values for those elements. In Html page , you can put the option to add new row of elements or text fields by writing the java script or using JQuery API. Now, the question is that how to capture the values of dynamically generated text fields on the server. Using the servlet programming you can get the values by using getParameters() method that resultants the array of the parameter having the same name. But this limit you to naming the text fields in the HTML form. To ally this approach, you have to take the same name for t

In Process Mode of HSQLDB in web application.

If you want to use the database into your web application, you can use the HSQLDB in In_Process mode. In this mode, you can embed the HSQLDB into your web application and it runs as a part of your web application programm in the same JVM. In this mode, the database does not open any port to connect to the application on the hosing machine and you don't need to configure anything to access it. Database is not expposed to other application and can not be accessed from any dabase tools like dbVisualizer etc. In this mode ,database will be unknown from any other person except you. But in the 1.8.0 version, you can use Server intance for external as well as in process access.  To close the databse, you can issue SHUTDOWN command as an SQL query.   In the in-process mode, database starts from JDBC with the associated databse file provided through  connection URL. for example   DriverManager.getConnection("jdbc:hsqldb:mydatabase","SA","");   Here myd