ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Advanced Computer Programming
    COMP3114
    Progress0 / 12 topics
    Topics
    1. Java API: Abstract classes and Interfaces2. Packages and Exception handling3. Advanced issues of GUI and event handling4. Applets and Swing5. Network Programming Concepts: JDBC6. Multithreading7. Building Client/Server and implementing protocols8. RMI (Remote Method Invocation)9. Java Secure Socket Extension and Secure Sockets Layer (SSL)10. SSL Socket and SSL Server Socket classes11. Client and Server Authentication: HTTPS12. Developing TCP/IP client and server with telnet
    COMP3114›RMI (Remote Method Invocation)
    Advanced Computer ProgrammingTopic 8 of 12

    RMI (Remote Method Invocation)

    3 minread
    561words
    Beginnerlevel

    📘 RMI (Remote Method Invocation) in Java


    🔷 1. Definition

    RMI (Remote Method Invocation) is a Java mechanism that allows an object in one Java Virtual Machine (JVM) to invoke methods of an object in another JVM over a network.

    👉 In simple words:

    RMI allows Java programs to call methods on remote computers as if they were local.


    🔷 2. Key Idea

    • Works in distributed systems
    • Uses client-server model
    • Hides network complexity from programmer

    📊 Concept Diagram (Description) Client JVM → Stub → Network → Skeleton → Server JVM


    🔷 3. RMI Architecture

    🔹 Main Components:

    1. Client

    • Calls remote method

    2. Stub (Client-side proxy)

    • Acts as local representative of remote object
    • Sends request to server

    3. Skeleton (Server-side handler)

    • Receives request
    • Calls actual method

    4. Remote Object (Server)

    • Executes method logic

    🔷 4. Working of RMI (Step-by-Step)

    ✔ Step-by-step process:

    1. Client calls remote method
    2. Stub converts request into network format
    3. Request sent to server
    4. Skeleton receives request
    5. Server executes method
    6. Result sent back to client
    7. Stub returns result to client

    🔷 5. RMI Architecture Diagram (Description)

    📊 Flow:

    Client → Stub → Remote Reference Layer → Skeleton → Remote Object → Response back


    🔷 6. Steps to Create RMI Application


    🔹 Step 1: Define Remote Interface

    import java.rmi.*;
    
    public interface MyRemote extends Remote {
        public String sayHello() throws RemoteException;
    }
    

    👉 Must extend Remote 👉 Methods must throw RemoteException


    🔹 Step 2: Implement Remote Interface

    import java.rmi.server.*;
    
    public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {
    
        public MyRemoteImpl() throws RemoteException {
            super();
        }
    
        public String sayHello() {
            return "Hello from Server";
        }
    }
    

    🔹 Step 3: Create Server

    import java.rmi.*;
    
    public class Server {
        public static void main(String[] args) {
            try {
                MyRemoteImpl obj = new MyRemoteImpl();
                Naming.rebind("rmi://localhost/hello", obj);
    
                System.out.println("Server started...");
            } catch(Exception e) {
                System.out.println(e);
            }
        }
    }
    

    🔹 Step 4: Create Client

    import java.rmi.*;
    
    public class Client {
        public static void main(String[] args) {
            try {
                MyRemote obj = (MyRemote) Naming.lookup("rmi://localhost/hello");
    
                System.out.println(obj.sayHello());
            } catch(Exception e) {
                System.out.println(e);
            }
        }
    }
    

    🔷 7. Key Classes in RMI

    Class Purpose
    Remote Marker interface
    RemoteException Handles network errors
    Naming Registry lookup/binding
    UnicastRemoteObject Remote object support

    🔷 8. RMI Registry

    👉 A registry service that stores remote objects.

    Commands:

    rmiregistry
    
    • Used to register and locate remote objects

    🔷 9. Advantages of RMI

    • Simple distributed programming
    • Object-oriented communication
    • Platform independent (Java-to-Java)
    • Easy remote method calling

    🔷 10. Disadvantages

    • Only works with Java
    • Slower than local method calls
    • Complex setup compared to sockets

    🔷 11. RMI vs Socket Programming

    Feature RMI Socket
    Level High-level Low-level
    Complexity Easy Complex
    Communication Method-based Data-based
    Language Java only Any language

    🔷 12. Important Rules

    • Remote interface must extend Remote
    • Methods must throw RemoteException
    • Objects must be registered in RMI registry
    • Use Naming.lookup() in client

    🔷 13. Diagram Description

    📊 RMI Flow Diagram:

    Client → Stub → Network → Skeleton → Remote Object → Response


    📝 Likely Exam Questions

    1. Define RMI.
    2. Explain RMI architecture.
    3. What are stub and skeleton?
    4. Steps to create RMI application.
    5. Write RMI client-server program.
    6. Difference between RMI and socket programming.
    7. What is Remote interface?
    8. Role of RMI registry.
    9. Advantages of RMI.
    10. What is RemoteException?

    📌 Quick Revision Summary

    • RMI = Remote Method Invocation

    • Calls methods across JVMs

    • Components:

      • Client
      • Stub
      • Skeleton
      • Server
    • Uses registry for lookup

    • Java-to-Java communication


    Previous topic 7
    Building Client/Server and implementing protocols
    Next topic 9
    Java Secure Socket Extension and Secure Sockets Layer (SSL)

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time3 min
      Word count561
      Code examples0
      DifficultyBeginner