20 RMI Interview Questions and Answers

Dear Readers, Welcome to RMI interview questions with answers and explanation. These 20 solved RMI questions will help you prepare for technical interviews and online selection tests conducted during campus placement for freshers and job interviews for professionals.

After reading these tricky RMI questions, you can easily attempt the objective type and multiple choice type questions on RMI.

RMI interview questions and answers for freshers and experienced candidates. These interview questions and answers on RMI will help you strengthen your technical skills, prepare for the interviews and quickly revise the concepts. Many candidates appear for the interview for one role - many of the them give the right answers to the questions asked. The one who provides the best answer with a perfect presentation is the one who wins the interview race. The set of RMI interview questions here ensures that you offer a perfect answer to the interview questions posed to you.

What is the method that is used by the RMI client to connect to remote RMI servers?

- RMI is known as Remote method invocation and to for the RMI client to connect to remote RMI server first thing is to get hold on a reference of the server.

- The Naming.lookup method is used to as a mechanism that is used to provide the way to obtain the references to remote servers. The remote servers can be obtained by using the remote calls that return remote references. This also uses a stub to make a remote method call used in rmiregistry that sends back to remote reference.

- Then the references consists of a server hostname and port number, which allow clients to locate a virtual machine. This virtual machine is used to allow the remote object to be found and connected. After the remote reference are provided to RMI client, then it will be easy to use hostname and port that is provided to open the socket connection to a remote server.

What is the function of java.net.UnknownHostException?

The java.net.UnknownHostException method is used as remote calling and for callback routine fail. RMI uses default settings to resolve the server hostname like WINS names, DHCP names, etc. This happens due to which RMI client invokes the remote method using the reference that consists of unresolved server hostname and the client will produce UnknownHostException. RMI servers provide fully qualified hostname or IP address to resolve all RMI clients error reports. RMI provides an operation to remotely callback a program that serves RMI object and provide resolvable hostname to pass it to the RMI clients. UnkownHostException is thrown when an applet is failed to provide a useable server hostname. The property java.rmi.server.hostname can be set to get from the server the correct IP address or hostname.

What are the reasons of getting UnknownHostException error even if all the setting are properly configured?

- The UnkownHostException error can come for many reasons. To find out first there is a need to know the network's name service that is having a fully-qualified hostname recognized by RMI host. The possible problems that might come are:

- There is a possibility of having misconfigured DHCP servers that allows fully-qualified domain name of RMI server machines. RMI client in this case try to access the outside server's DHCP domain that will make it unavailable for the server.

- There is a possibility of having the error due to WINS server. It is possible that only registered users might not be reachable by hosts.

- There is a possibility of having a firewall that is blocking the RMI client and server side requests. If the server resides inside the firewall and the client outside then the client won't be able to make any remote calls to the server that is inside due to the firewall.

What is the use of HTTP-tunneling in RMI?

- HTTP-Tunneling is a method that requires no setup and works within the firewall environment. It allows the handling of HTTP through proxy server and doesn't allow regular outbound TCP connections. If the RMI fails to make any connection specially SOCKS then connection is made through an intended server that allow the HTTP proxy server to be configured. This will allow the request to be passed through the proxy server one by one. The forms of HTTP-tunneling are http-to-port: where the RMI attempt to use HTTP POST request using a URL that will be directed at the hostname and port number of the server that is given. If the proxy accepts the URL it will forward a POST request to listen to RMI server that will remove the request of the name. There is an http-to-cgi tunneling that will consists of the requests and allow the proxy request to be binded to their defined port numbers.

How does distributed garbage collectior manges the disconnections detected on the client side?

RMI uses a runtime client that a virtual machine detects of the remote object that is not referenced locally. It notify the server in came of any disconnections and this way the server can be updated by the object's set. The garbage collector that is distributed associate an address with each client remote object reference. It also renew the remote objects while the client still consists of the references. This mechanism will allow the abnormal termination of the clients so that server can hold the remote objects that are not referenced using the message that are stopped running. The function System.exit() can be invoked for abnormal termination, as it doesn't allow the RMI runtime to send a proper messages to the server. This function will terminate the client virtual machine and will keep the remote references that will be cleaned up before exiting. The other functions that are used for this are:
System.gc();
System.runFinalization();

What is the relationship between the RMI and CORBA?

RMI is a distributed object system that provides and enable to easily develop the distributed Java applications. It is easier to develop applications using the RMI method then using the sockets. It doesn't require any protocol for design that makes it less prone to error for the tasks performed by it. RMI is allows the local method to be called from a local class file and the remote methods are interpreted and are sent back to the callers. The CORBA also having the same features that are seen in RMI. It is a platform and language independent architecture that can be run on any platform. It can be located from anywhere on the network and can be used in any language that has a mapping with IDL (Interface definition language). The objects of this are specified with interfaces that are specified in the interface language.

What are the different terms that are used in RMI?

- There are different terms that are used in RMI that helps in calling the remote servers and allow an easy to use terminology to be created:

Remote object:
- It is an object that is provided on another computer to request the object by sending a message to the object to the remote servers.

Server object:
- It is an object of the server side that receive the request and respond to the request of the client in success or failure.

rmiregistry:
- It is the registry that keeps the look ups of all the objects in a list by given name.
- This registry consists the list of all the components that are given in it.

Rmic:
- It is a compiler for RMI object.
- After creating the object the compiler compiles the object and it will generate the actual code that is to be transferred to the client side.

What are the different types of classes that are used in RMI?

- The classes define the blueprint that consists of the methods and behavior of a particular structure.
- The classes are:

Remote class:
- It is the class that consists of the instances that can be accessed remotely from the server and also consists of different properties that are required to be accessed by the client and server during request and response time.

Remote class object:
- Wherever this object is defined the instances of the class can be accessed using other object.
- On other computers that are not in network it can be accessed through the use of object handles.

Serializable class:
- It is the class that consists of instances that can be marshaled or turned in a linear sequence to represent the bits.

Serializable class objects:
- It allows the request to be transmitted from one computer to another.
- It allows the easy implementation of the serializable class.

What are the different conditions that has to be kept in mind when using serialization concept?

The conditions that has to be kept in mind while using serialization is that:

- The class should be declared as public and it should implement the serializable version identifier that is given as serialVersionUID to read the serial versions that are being loaded or updated.

- The class should not consists of any argument constructor and all the fields of the class should have a serializable field in it. This can be either primitive types or Serializable objects type.

- The class doesn't itself declare any methods and an execption can be made in the fields that are made transient and these are ignored during serialization.

What is the process of making a class serializable?

- To create a class serializable there is mechanism of serializing an object on the client code.
- There are four things that are required to make a class serializable and these are:

1. The first thing that has to be done is to implement the serializable interface that makes the process easy to convert the set of object references to the linear stream of bytes.

2. Check whether the instance level that is locally defined state is in serialized mode or not. Check that it has been implemented properly or not.

3. Check whether the superclass state in the serialized phase is properly managed and adjusted. If it is adjusted then with the help of few function the process can create a class serializable.

4. Then use the methods like equals( ) and hashCode( ) to override the already used functions. This will allow the addition of new code to be inserted.

What is the procedure of implementation of the Serializable Interface?

- The implementation is the easy phase of the serializable class. At first this interface remains as an empty interface and it declares no methods or behavior at all. It has additing feature that is added to the implements serializable class to follow the class declarations. It is not required to make every object as serializable as there will also be some classes that might not be having any serialization required.

- For example, an instance of a file that actually represents a file gets created by using
File file = new File("c:\\career\\ride");
- so to make this work there is no surity that is it require a serialized code to be written. The file class is having a different lifecyle than the serialized data and modification in it might remove the entire information. There are also platform dependencies that involves native code not used for serialization.

What is the main purpose of Distributed object applications in RMI?

RMI consists of a server and a client program. The application in RMI creates a number of remote objects that makes the references to the objects that are to be accessible. This way when a client makes a call to the method on remote objects then the reference is passed to one or more remote objects in server. It then invokes certain methods on them to provide few functionalities. RMI provides the mechanism to communicate and pass the information from one part to another using the distributed object applications. It requires to locate the remote objects so that the registry can be maintained for the remote objects with RMI's naming facility, rmiregistry, and the application that can pass the remote object references and return it as a normal operation.

How does the communication with remote objects occur in RMI?

RMI handles the remote objects that are being provided between the server and client computers. The difference between the objects are handled using RMI as well. RMI uses the standard method invocation to communicate between one object or another object. It loads the class byte-codes for objects that are passed using the defined parameters and return the values to the server in case of failure or success of it. RMI also allows the transmission to be done when passing the data as well. The string that is used by the RMI registry is “rmi://hostname:port/remoteObjectName", this allows the RMI registry to know the correct object and create a connection between different objects through this. If the hostname is not defined then local host can be used instead of it and this will also establish the connection.

What are the steps that are involved in RMI distributed applications?

RMI distributed applications uses certain steps that defines the path mentioned in the registry. It has the following steps:

- It uses the registry that stores the location and important information about the remote object.

- It uses the registry to obtain the references to a remote object that keeps all the information and allow further communication to be done.

- The server calls the registry to associate the name with the remote object and then the client sends the request for the object.

- The client searches the remote object by its name in the registry on the server and invokes a method on it.

- RMI uses a web server to load the bytecodes of classes to use the communication for the client and server.

- RMI can load the class using the Internet protocols like HTTP, FTP, file, and etc.

What is the use of java.rmi.Remote Interface in RMI?

- RMI uses a remote interface declaring the methods that are invoked from a virtual machine and further forwarded to the server to take any request coming from the client.

- Java.rmi.Remote provides an interface declaring a set of methods that invokes the virtual machine to fulfill the requirements.

- This allows the extension of the interface directly or indirectly.

- Each method declaration in remote interface must have the exception policy such as java.rmi.RemoteException or java.io.IOException or java.lang.Exception clause that can be made application specific and it reduces the effort to extend java.rmi.RemoteException.

- Remote method declares the object as a parameter or the return value and that has to be declared using the remote interface.

Write a program to show the remote interface using RMI.

- Remote interface allows the extension of the interface of java.rmi.Remtoe.

- This interface extends it non-remotely using the condition that this extend the interface when all the methods used are also extended in the interface that satisfy all the requirements of a remote method declaration.

- The example code shows the remote interface that is used in general:
public interface Bank extends java.rmi.Remote
{
   public void deposit(float amount)
   throws java.rmi.RemoteException;
   public void withdraw(float amount)
   throws OverdrawnException, java.rmi.RemoteException;
   public float getBalance()
   throws java.rmi.RemoteException;
}
- The class of this extends the java.rmi.Remote to inherit the behavior and properties used by this specified class.

- This also uses several other class objects for example:
java.rmi.server.RemoteObject and
java.rmi.server.RemoteServer.

Write a program to show the distributed object model using RMI.

- To implement the distributed object model a class is required that implements a remote interface extending the functionality of java.rmi.Remote and other classes such as java.rmi.server.UnicastRemoteObject.

- The implementation then take the responsibility for exporting the object having the correct use of remote semantics provided using hashCode, equals, and toString methods that are inherited from the java.lang.Object class.

- The code is given below as:
public void withdraw(float amount) throws OverdrawnException,
RemoteException
{
   // write your own statements
}
public float getBalance() throws RemoteException
{
   // write your own statements
}

Why are stubs used in RMI?

RMI uses a mechanism that is standard for all the system and it is used to communicate with all the remote objects that are available. So, stubs are used to store the objects in the database so that it can be used later on. A stub is used for remote objects that act as a client’s local proxy for the remote object. This way the caller of the object calls the method on the local stub that becomes responsible to carry out the method call on the remote objects. RMI uses stub for a remote object that implements the same set of remote interfaces that is implemented by remote object. The stub is used to initiate the connection between the object and the java virtual machine. It marshalls that includes write and transmit the parameters to the remote java virtual machine that includes the method invocation. It allows the unmarshalling of the object to return the true value or the exception to be returned to the caller. The stub is used to hide the serialization of the parameter at network-level for the communication to be proceeded without any disturbance.

Why is the function or role of skeleton in RMI?

Every object that can be remotely accessed have a corresponding skeleton that functions like the original object. It is responsible for dispatching the call that is made to the actual remote object for the implementation and allow it to be implemented using the services provided by RMI. It allows the incoming method invocation to unmarshals i.e. only read the parameters used for the remote method. It invokes the method that is used by the actual remote object and after implementation marshals the result to the caller who is the original caller for the object.

How does dynamic class loading happens in RMI?

- RMI uses different parameters with values and exceptions and they all has to be passed for RMI calls. It creates the object that is serializable.

- RMI uses the serialization mechanisms to transfer the data from one machine to another using the virtualization concept. This is done so that the caller can receive the files on time. When the parameters return the values of the method invocation and unmarshals it then the live objects gets received by the java virtual machines.

- The unmarshalling process tries to resolve the name issue of the classes by loading the context class using the current thread. RMI provides the dynamic loading of the class definition to be done using actual types of objects that are passed as parameters and return values for RMI.
- This allows the dynamic loading of the remote stub classes that are related to a particular remote object that takes part in implementation of the classes.

- RMI also uses special subclasses of java.io.ObjectOutputStream and java.io.ObjectInputStream for marshilling and unmarshalling.
What is Remote Procedure Calls, RPC?
Remote Procedure Calls, RPC - A request from one program that is located in one computer can be used by another computer in a network environment without understanding the underlying network details....
Explain the advantages and disadvantages of RPC
Advantages and disadvantages of RPC - Server independent, Process-oriented and thread oriented models supported by RPC...
RMI - Explain the difference between RPC and RMI
Difference between RPC and RMI - The remote objects are accessed by the references....
Post your comment