2. What is RMI?
RMI stands for Remote Method Invocation. It is a
mechanism that allows an object residing in one
system (JVM) to access/invoke an object running
on another JVM.
RMI is used to build distributed applications; it
provides remote communication between Java
programs. It is provided in the package java.rmi.
Remote objects must be written in Java
object-oriented (Object provide methods). objects
on different computers can interact in a distributed
network.
RMI basically provides remote object access for a
client and object registration for servers.
3. RMI Components
Client: The client looks
up a remote object and
calls methods on the
obtained remote object.
Server: The server
registers itself in the RMI
registry and accepts
method invocations from
the client.
RMI Registry: The
registry is a remote
object lookup service.
4. What is RMI Registry?
Essentially the RMI registry is a place for the server to
register services it offers and a place for clients to query
for those services.
Firstly, the client must contact an RMI registry, and
request the name of the service.
This will point him in the direction of the service he
wants to call.
RMI Registry acts a broker between RMI servers and the
clients. The server "registers" its services in the registry
- hence a RMI Registry can act as a "directory" for many
servers/services. The client does not need to know the
location of individual servers, and does a lookup on the
RMI Registry for the service it needs. The registry, being
a naming directory returns the appropriate handle to the
client to invoke methods on.
5. Architecture of an RMI
Each time the server creates an object, it registers this object
with the RMIregistry (using bind() or reBind() methods).
To invoke a remote object, the client needs a reference of that
object. At that time, the client fetches the object from the
registry using its bind name (using lookup() method).
7. Understanding stub and skeleton
stub
The stub is an object, acts as a gateway for the client side.
All the outgoing requests are routed through it.
It resides at the client side and represents the remote object.
When the caller invokes method on the stub object,
it does the following tasks:
1.It initiates a connection with remote Virtual Machine (JVM),
2.It writes and transmits (marshals) the parameters to the
remote Virtual Machine (JVM),
3.It waits for the result
4.It reads (unmarshals) the return value or exception, and
5.It finally, returns the value to the caller.
8. skeleton
The skeleton is an object, acts as a gateway for the server
side object.
All the incoming requests are routed through it.
When the skeleton receives the incoming request,
it does the following tasks:
1.It reads the parameter for the remote method
2.It invokes the method on the actual remote object, and
3.It writes and transmits (marshals) the result to the caller.
9. What is an interface in Java?
Interface looks like a class but it is not a class. An interface
can have methods and variables just like the class but the
methods declared in interface are by default abstract (only
method signature, no body, see: Java abstract method).
Also, the variables declared in an interface are public, static
& final by default.
What is the use of interface in Java?
As mentioned above they are used for full abstraction.
Since methods in interfaces do not have body, they have to
be implemented by the class before you can access them.
The class that implements interface must implement all the
methods of that interface. Also, java programming
language does not allow you to extend more than one
class, However you can implement more than one
interfaces in your class.