1. What are the services in RMI?

An RMI "service" could well be any Java method that can be invoked remotely. The other service is the JRMP RMI naming service which is a lookup service.

2. Explain RMI Architecture?

RMI uses a layered architecture, each of the layers could be enhanced or replaced without affecting the rest of the system. The details of layers can be summarised as follows:

1. Application Layer: The client and server program
2. Stub & Skeleton Layer: Intercepts method calls made by the client/redirects these calls to a remote RMI service.
3.Remote Reference Layer: Understands how to interpret and manage references made from clients to the remote service objects.
4.Transport layer: Based on TCP/IP connections between machines in a network. It provides basic connectivity, as well as some firewall penetration strategies.

3. In a RMI Client Program, what are the excpetions which might have to handled?

a. MalFormedURLException
b. NotBoundException
c. RemoteException

4. What is PortableRemoteObject.narrow() method and what is used for?

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 javax.rmi.PortableRemoteObject class and, more specifically, using the narrow() method.

5. What does the exportObject of UnicastRemoteObject do?

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.

6. What is the use of UnicastRemoteObject in RMI?

The UnicastRemoteObject class provides support for point-to-point active object references using TCP streams. Objects that require remote behavior should extend UnicastRemoteObject.

7. What is the protocol used by RMI?

JRMP(java remote method protocol)

8. Can a class implementing a Remote interface have non remote methods?

Yes. Those methods behave as normal java methods operating within the JVM.

10. When is AlreadyBoundException thrown and by which method?

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.

Download Interview PDF