The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

41.Discuss in brief about Remote Method Invocation (RMI) and its working?

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.

42.What is the difference between RMI and JMS?

RMIJMS
RMI is tightly-coupled mechanism.JMS provides loosely coupled mechanism.
The destination object need to be available online at the time of sending messages from client to server.The destination object need not be available online at the time of sending messages from client to server.
RMI has RPC-modelJMS has messaging model.

43.What is Registry Service for RMI?

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.

44.Explain how URL convention is used for accessing the registry?

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:
java -Djava.rmi.server.codebase=http://host/username/codebase/examples.ExampleRMIURL

45.Explain how to bind an object to the registry.?

If an object implements the java.rmi.Remote interface, an object is to be bound to registry context. Each registry context implements the Referenceable interface.

The object factory is implemented by the RegistryContextFactory which converts the registry references into the corresponding registry contexts or remote objects. To construct the registry constructs, the URL of the registry must be determined. In this way the remote objects will be bounded with registry contexts.

46.Explain the various methods of registering and gaining access to the Remote Object?

The methods of remote objects are to be invoked by implementing the java.rmi.Remote interface.

Methods:

bind(): binds the specified name to the remote object. The name parameter of this method should be in an URL format.

unbind(): Destroys the binding for a specific name of a remote method in the registry

rebind(): Binds again the specified name to the remote object. The current binding will be replaced by rebinding.

list(): Returns the names of the names that were bound to the registry in an array form. These names are in the form of URL-formatted string.

lookup(): A stub, a reference will be returned for the remote object which is related with a specified name.

47.Explain the steps to create RMI-based clients and server?

Creation of RMI-based Server:

* Create the Servant interface and the Servant component class
* To host these servant classes create the RMI Server
* Compile the class files and generate the Skeletons and IDL File
* Start up the Server

Creation of RMI-based Client:

* Create the Client class
* Copy the IIOP Stubs and compile the Client
* Make sure the Server is running and then startup the Client

48.What are Remote callbacks?

In client-server technology / architecture, a server responds to a remote client. A call back is a method invocation from one application (Application A) from another application (Application B), as a result of action that was performed by the Application B earlier. The Application A may run on a client and the Application may run on a server. To perform the call back mechanism the system that Application A runs acts as a Server and that of the Application B runs acts as a client.

49.What is Object Activation?

Object Activation is a process of providing persistent references to the objects. It also includes the managing the execution of implementing of objects. RMI activates the objects for the execution as and when needed. The appropriate execution is initiated inside the appropriate JVM when the activatable remote object is accessed which is not currently running.

• 1
• 2
• 3
• 4
• 5
• 6
• 7

50.What is data transfer in RMI model?

Data in a file can be transferred by using the method getFileContents(filename) in the remote interface.

RMI supports to transfer data that is available in JDOM data objects.

51.What is object serialization in RMI?

To marshal and unmarshall the parameters involves the object serialization and does not truncate types.

The methods of local object and their bytecodes are not passed directly in the ObjectOutputStream. At times the name of the class of the objects may be needed that is to be loaded by the receiver if at all the class is not available locally. Just like the names of the classes, the class files themselves will not be serialized. All classes must load during the process of deserialization using the normal mechanisms of class loading.

52.What is RMI callback mechanism?

When one service passes an object which is the proxy for another service, the RMI callback mechanism occurs. The methods will be invoked by the recipient in the object it received and be calling back to the calling point. The stub contains the information that is needed to call back to server at the time of the need.

53.What is the role of Remote Interface in RMI?

Remote interfaces are defined by extending ,an interface called Remote provided in the java.rmi package. The methods must throw RemoteException. But application specific exceptions may also be thrown.

54.Explain marshalling and demarshalling.

During communication between two machines through RPC or RMI, parameters are packed into a message and then sent over the network. This packing of parameters into a message is called marshalling.

On the other side these packed parameters are unpacked from the message which is called unmarshalling.

55.What is a skeleton in RMI?

Server side stub is refered to as a skeleton.

56.Explain the role of stub in RMI.?

The role of the stubs is to marshal and unmarshal the messages that are sent and received on the client or the server side.

57.What are the layers on which RMI implementation is built? Explain them.?


The Stub/Skeleton Layer:
The stub/skeleton layer sits in between application layer and the rest of the RMI system and acts as an interface. This layer transmits the information to remote layer. This transmission is done through the marshalling of streams. These streams performs the object serialization.
A stub is a remote object at the client-side. This stub implements all the interfaces which remote object implementation supports.
A skeleton is a remote object at the server-side. This stub consists of methods that invokes dispatch calls to the remote implementation of objects.

The Remote Reference Layer:
The lower level transport interfaces is dealt by this layer. This layer carries a specific remote reference protocol independent of stub and skeletons.
Every remote object is implemented by choosing their individual remote reference subclasses.

The Transport Layer:
The transport layer sets up the connections to remote address spaces, manages them, monitors the connection liveliness, and listens the incoming calls.
The transport layer maintains the remote object’s table available in the address space, in a table. For incoming calls, the transport layer establishes a connection. It locates the target dispatcher of the remote calls and passes the connection to the dispatcher.

58.Explain how RMI clients contact remote RMI servers.

* The client procedure calls the client stub in the normal way.
* The client stub builds a message and traps to the kernel.
* The kernel sends the message to the remote kernel.
* The remote kernel gives the message to the server stub.
* The server stub unpacks the parameters and calls the server.
* The server does the work and returns the result to the stub.
* The server stub packs it in a message and traps to the kernel.
* The remote kernel sends the message to the clients kernel.
* The clients kernel gives the message to the client stub.
* The stub unpacks the result and returns to the client.

59.What are the basic steps to write client-service application using RMI?

* Assigning the security manager and then obtaining the reference to the service
* Contacting the RMI registry to obtain the remote object’s reference and invoking its methods
* Requesting the name for the service
* Invoke the remote method.

60.What is Unicast and Multicast object?

The difference between unicast and multicast is that in unicast approach the sender sends the data stream to a single receiver at a time. Thus there is one to one communication.

In a multicast the sender and the interested receivers communicate. This is one to many communication. This communication can take place between data terminals spread across various LANs too.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com