RMI Interview Questions
1 what is RMI?
Ans: Remote Method Invocation (RMI) is the process of activating a method on a remotely running object. RMI offers location transparency in the sense that it gives the feel that a method is executed on a locally running object.
2 what is the basic principle of RMI architecture?
Ans:The RMI architecture is based on one important principle: the definition of behavior and the implementation of that behavior are separate concepts. RMI allows the code that defines the behavior and the code that implements the behavior to remain separate and to run on separate JVMs.
3 what are the layers of RMI Architecture?
Ans: The RMI is built on three layers.
a. Stub and Skeleton layer This layer lies just beneath the view of the developer. This layer intercepts method calls made by the client to the interface reference variable and redirects these calls to a remote RMI service.
b. Remote Reference Layer. This layer understands how to interpret and manage references made from clients to the remote service objects. The connection is a one-to-one (unicast) link.
c. Transport layer This layer is based on TCP/IP connections between machines in a network. It provides basic connectivity, as well as some firewall penetration strategies.
4 what is the role of Remote Interface in RMI?
Ans: The Remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. Methods that are to be invoked remotely must be identified in Remote Interface. All Remote methods should throw Remote Exception.
5 what is the role java.rmi.Naming Class?
Ans: The Naming class provides methods for storing and obtaining references to remote objects in the remote object registry.
6 what is the default port used by RMI Registry?
Ans: 1099
7 what is meant by binding in RMI?
Ans: Binding is a process of associating or registering a name for a remote object that can be used at a later time to look up that remote object. A remote object can be associated with a name using the Naming class’s bind or rebind methods.s
8 what is the difference between using bind () and rebind () methods of Naming Class?
Ans: The bind method (String name) binds the specified name to a remote object while rebind (String name) method rebinds the specified name to a new remote object; any existing binding for the name is replaced.
9 When is Already Bound Exception thrown and by which method?
Ans: AlreadyBoundException is thrown by bind (String name) method when a remote object is already registered with the registry with the same name.
Note: rebind method doesn’t throw AlreadyBoundException because it replaces the existing binding with same name.
10 How to get all the registered objects in a registry?
Ans: Using list method of Naming Class.
11 Can a class implementing a Remote interface have non remote methods?
Ans: Yes. Those methods behave as normal java methods operating within the JVM.
12 what is the protocol used by RMI?
Ans: JRMP (java remote method protocol)
13 what is the use of? Uni cast Remote Object in RMI?
Ans: The UnicastRemoteObject class provides support for point-to-point active object references using TCP streams. Objects that require remote behavior should extend UnicastRemoteObject.
14 what does the export Object of UnicastRemoteObject do?
Ans: Exports the remote object to make it available to receive incoming calls, using the particular supplied port. If port not specified receives calls from any anonymous port.
15 what is Portable Remote Object.narrow () method and what is used for?
Ans: Java RMI-IIOP provides a mechanism to narrow the the Object you have received from from your lookup, to the appropriate type. This is done through the java x.rmi. PortableRemoteObject class and, more specifically, using the narrow() method.
16 In a RMI Client Program, what are the excpetions which might have to handle?
Ans: a. MalFormedURLException
b. NotBoundException
c. RemoteException