ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3114Rmi
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3114

    Advanced Computer Programming

    Progress0 / 12 done
    Topics12
    1Abstract classes and Interfaces2Packages and Exception handling3Advanced issues of GUI and event handling4Applets and Swing
    5JDBC6Multithreading7Building Client/Server and implementing protocols8RMI (Remote Method Invocation)9Java Secure Socket Extension and Secure Sockets Layer (SSL)10SSL Socket and SSL Server Socket classes
    11HTTPS12Developing TCP/IP client and server with telnet
    3 min read
    Topic 8 of 12
    Topic Study Note Illustration
    08

    RMI (Remote Method Invocation)

    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...

    πŸ“˜ 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 view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    3mremaining
    561words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Advanced Computer Programming