9 Distributed Programming With Rmi

Advanced Java Programming · Unit 9

Distributed Programming with RMI

Exam-focused notes for Distributed Programming with RMI (Advanced Java Programming, BIT401): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.

Distributed Programming with RMI in short

Remote Method Invocation (RMI) lets a Java program call a method of an object that lives in another JVM, maybe on another computer. The call looks like a normal method call.

Distributed Programming with RMI: notes

RMI architecture and components

The architecture has a client, a server and a registry.

  • Remote interface: lists the methods that clients may call. It extends java.rmi.Remote, and every method throws RemoteException.
  • Remote object (server implementation): the class that implements the interface. It usually extends UnicastRemoteObject.
  • Stub: a client-side proxy. It packs (marshals) the arguments and sends the call over the network.
  • Skeleton: the server-side helper in old versions. It unpacks (unmarshals) the arguments and calls the real object. Modern Java creates this part automatically.
  • RMI registry: a naming service. The server binds a name to the object, and the client looks the name up.
  • Transport layer: carries the call between JVMs. It uses the JRMP protocol by default.
Client -> Stub -> network -> (Skeleton) -> Remote object
            ^
        Registry lookup

The server registers the object. The client looks it up in the registry and receives a stub. It then calls methods on the stub as if they were local. Arguments and results are sent by serialization, so they must be Serializable.

What this unit covers

  • RMI architecture and components
  • Steps of writing RMI programs
  • Remote objects and interfaces
  • RMI registry and naming
  • RMI versus CORBA comparison

RMI versus CORBA comparison

2082 · 5 marks

Differentiate between RMI and CORBA. [5]

Show solved answer

Model Answer: RMI vs CORBA

Key Differences

AspectRMICORBA
LanguageJava-onlyLanguage-independent
PlatformPlatform-dependentPlatform-independent
ProtocolJava Remote Method Protocol (JRMP)Internet Inter-ORB Protocol (IIOP)
ComplexitySimpler to implementMore complex
PerformanceFaster (optimized for Java)Slower (due to protocol overhead)
InteroperabilityLimited to Java systemsWorks across different languages and platforms

Detailed Comparison

RMI (Remote Method Invocation):

  • Designed specifically for Java-to-Java communication
  • Uses serialization for object marshalling
  • Tightly coupled to Java Virtual Machine (JVM)
  • Easier learning curve for Java developers
  • Better performance within homogeneous Java environments

CORBA (Common Object Request Broker Architecture):

  • Vendor-neutral, language-neutral standard
  • Supports multiple programming languages (C++, Python, Ada, etc.)
  • Uses Interface Definition Language (IDL) for service definition
  • Provides greater flexibility for heterogeneous systems
  • Suitable for enterprise-wide distributed systems with mixed technologies

When to Use

  • Use RMI: When building distributed systems entirely in Java
  • Use CORBA: When integrating systems written in different programming languages or across diverse platforms

Note: This answer is based on standard distributed systems concepts. Refer to your course materials for any institution-specific emphasis.

Open this answer on its own page →

RMI architecture and components

2081 · 5 marks

Explain the architecture of RMI. [5]

RMI is a Java mechanism that allows a program running on one JVM to invoke methods on objects residing in another JVM. The architecture consists of the following layers: - Contains the client and server applications - Client invokes remote methods as if they were local - Server implements the rem...

Open this answer on its own page →

2080 · 5 marks

How distributed programs can be written in Java? Explain RMI architecture. [5]

Distributed programs in Java can be written using several approaches: 1. Socket Programming - Using TCP/IP sockets for low-level network communication between Java applications 2. RMI (Remote Method Invocation) - Allows Java objects to invoke methods on remote Java objects as if they were local 3...

Open this answer on its own page →

Steps of writing RMI programs

0 · 5 marks

Discuss the steps of writing RMI programs. [5]

RMI (Remote Method Invocation) allows Java programs to invoke methods on objects located in other JVMs across a network. Writing RMI programs involves a structured sequence of steps. - Create an interface that extends java.rmi.Remote - Declare all methods that will be remotely accessible - All me...

Open this answer on its own page →