RMI Interview Questions and Answers
Ques 11. Explain the difference between RPC and RMI.
* The remote objects are accessed by the references
* Implements object to object implementation among different java objects to implement distributed communication model.
- RMI passes the objects as parameters to remote methods.
- RMI invokes the remote methods from the objects
* The process is through methods / functions
* Proxy server is involved in processing the procedure calls
* Calls a procedure remotely like invoking the methods
* The remoteness is not exactly transparent to the client
Ques 12. Discuss in brief about Remote Method Invocation (RMI) and its working.Ans. RMI is a java object equivalent process that invokes a method in a distributed environment.
RMI performs the communication among objects using object-to-object communication. RMI uses the objects distribution techniques and invokes methods of objects which are located in a remote site.
Working of RMI:
The code from machine A is being accessed for the object that is residing on machine B in a remote relocation. There are two intermediate objects called a 'stub' and a 'skeleton', which actually handles the communication. The following are the tasks that performed by these two objects:
Task that are to be handled by the stub object (on machine X):
* Building a information block which consists of
- an identifier of the remote object
- an operation number that describes the method to be called and
- the method parameters called marshaled parameters that are to be encoded into a suitable format for transporting over the network
* Sending the information to the server.
The tasks that are to be handled by the skeleton object (on machine Y) are:
* Unmarshalling the parameters
* Invoking the required method of the object which is lying on the server
* Capturing and returning the value if successful or an exception if unsuccessful , after the call on the server
* Marshalling the returned value
* Packaging the value that is in the marshaled form and sending to the stub on the client.
Subsequently the stub object unmarshals the return value or exception from the server as the case may be. This is the returned value of the remote method invocation. If an exception is thrown, the stub object will rethrow the exception to the caller.
Ques 13. What is the difference between RMI and JMS?Ans.
* RMI is tightly-coupled mechanism.
* The destination object need to be available online at the time of sending messages from client to server.
* RMI has RPC-model
* JMS provides loosely coupled mechanism.
* The destination object need not be available online at the time of sending messages from client to server.
* JMS has messaging model.
Ques 14. What is Registry Service for RMI?Ans. The registration of the remote object must be done by the server in order for the client to look it up, is called the RMI Registry. In RMI, the client must contact an RMI registry, so that the server side application will be able to contact the clientís registry which points the client in the direction of the service. The client registers the service with the registry so that it is transparent to even for the server.
Ques 15. Explain how URL convention is used for accessing the registry.Ans. The class rebind () method of java.rmi.Naming class is used to specify the port number . For example if the registry is running on a port number 3271 of an application named HelloRMIRegistry the following is the usage of the URL to reference the remote object:
Naming.rebind ("//host:1111/RMIRegistry", obj);
The URL stored on the web page needs to specify the non-default port number.
When the serverís remote objects created by the server can include the URL from which the stub class can dynamically be downloaded to the client. The following example depicts this:
Most helpful rated by users: