Remote Method Invocation (RMI) Interview Questions in Java

List of topic-wise frequently asked java interview questions with the best possible answers for job interviews.

Remote Method Invocation (RMI) Interview Questions in Java

Question 1.
What are RMI and the steps involved in developing an RMI object?
Answer:
Remote Method Invocation (RMI) allows java objects that execute on one machine and invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are:

  • Define the interfaces.
  • Implementing these interfaces
  • Compile the interfaces and their implementations with the java compiler
  • Compile the server implementation with the RMI compiler
  • Run the RMI registry
  • Run the application

Question 2.
What is RMI architecture?
Answer:
RMI architecture consists of four layers and each layer performs specific functions:

a) Application layer                ——-     contains the actual object definition
b) Proxy layer                         ——-     consists of stub and skeleton
c) Remote Reference layer     ——-     gets the stream of bytes from the transport layer and sends it to the proxy layer
d) Transportation layer          ——-     responsible for handling the actual machine-to-machine communication

Question 3.
What is UnicastRemoteObject?
Answer:
All remote objects must extend UnicastRemoteObject, which provides functionality that is needed to make objects available from remote machines.

Question 4.
Explain the methods, rebind( ) and lookup( ) in Naming class?
Answer:
rebind( ) of the Naming class(found in java.rmi) is used to update the RMI registry on the server machine.
Naming. rebind(“AddSever”, AddServerlmpl);
lookup( ) of the Naming class accepts one argument, the rmi URL, and returns a reference to an object of type AddServerlmpl.