MCS024 : Question 4 (a) RMI in Java | Creating Stub and Skeleton for RMI | June 2023 Paper Solution

mcs024 june 2023 Paper

Question 4(a) What is RMI in Java ? Write the steps to create stub and skeleton.


Answer:

RMI (Remote Method Invocation) in Java:
RMI, or Remote Method Invocation, is a mechanism in Java that allows objects residing in one JVM (Java Virtual Machine) to invoke methods on objects residing in another JVM, even if they are on different physical machines or networked environments. It enables distributed computing and facilitates communication between Java objects across a network.

Steps to Create Stub and Skeleton in RMI:

To create a remote object and enable RMI communication, the following steps are involved in creating the stub and skeleton:

1. Define the Remote Interface:
  • Create an interface that extends the "java.rmi.Remote" interface.
  • Declare the remote methods that can be invoked by the client.
  • Each remote method must throw "java.rmi.RemoteException".

2. Implement the Remote Interface:
  • Create a class that implements the remote interface.
  • Provide the implementation for each remote method declared in the interface.
  • This class will serve as the server-side implementation of the remote object.

3. Compile the Remote Interface and Implementation:
  • Compile both the remote interface and its implementation class.

4. Generate the Stub and Skeleton:
  • Use the "rmic" tool (RMI Compiler) provided by Java to generate the stub and skeleton classes.
  • Run the "rmic" command followed by the fully qualified name of the remote implementation class.
  • This step generates the stub and skeleton classes for the remote object.

5. Start the RMI Registry:
  • Start the RMI Registry on the server-side to enable clients to locate the remote object.
  • This can be done by running the "rmiregistry" command from the command line.

6. Deploy and Run the Server and Client:
  • Start the server program by instantiating the remote object and binding it to a unique name using "Naming.rebind()".
  • Run the client program by looking up the remote object from the RMI Registry using "Naming.lookup()".
  • The client can then invoke remote methods on the object obtained from the lookup.

By following these steps, the stub (client-side) and skeleton (server-side) classes are generated, enabling remote method invocation between client and server objects using RMI in Java.

Post a Comment

0 Comments