Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:50:51+00:00 2026-06-06T07:50:51+00:00

I have read various articles about passing variables around using RMI. Some of them

  • 0

I have read various articles about passing variables around using RMI.

Some of them say that it is impossible to pass variables by references in RMI. e.g.: this one and this one

While others says that it is possible. e.g.:
this one, this one and this one

can anyone clear this up please? 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:50:54+00:00Added an answer on June 6, 2026 at 7:50 am

    Important note: if pass by reference means modifying argument value inside the method and change original variable in caller, you can’t. If what you want to do is passing a copy of a reference to an object, to allow the method interact with some object of yours… yes you can. The answer explores that second option.

    Yes. But it has to be an RMI object. In that case a RMI stub will be passed by copy.

    RMI passes arguments and return values two ways:

    1. copy the full object
    2. send a remote reference (it has to be remote if its a reference!).

    Sample

    Guess we have a Service. It’s a RMI object, published through the RMI registry, so it’s accesible to clients. Client can call a method on it (to create something) and the service wants to return a reference to that newly created object. Not a serialized copy but a reference to the created object in server memory space.

    import java.rmi.Remote;
    import java.rmi.RemoteException;
    
    // normally published object
    public interface MyService extends Remote
    {
        // creates something and return a "handle" to it
        public MyHandle createX(SomeSerializableObj param1) throws RemoteException;
    }
    
    // interface for object that the service will return a reference to...
    public interface MyHandle extends Remote
    {
        void doOne();
        void doTwo();
    }
    

    In this example you could:

    Create an implementation of MyService and publish it

    Registry registry = LocateRegistry.createRegistry(port);
    MyService stub = (MyService) UnicastRemoteObject.exportObject(server, 0);
    registry.bind("myService", stub);`
    

    and then, some RMI client could get a reference to it

    Registry registry = LocateRegistry.getRegistry(server, port);
    MyService serv1 = (MyService) registry.lookup("myService");
    

    and with a reference to the service object could obtain a reference to other RMI object.

    MyHandle handle1 = serv1.createX(...);
    handle1.doOne()
    

    In this example the method argument is serialized (it should be a Serializable class)
    while the returned object is a RMI reference to an object created in the server.

    The implementation of createX(…) could be:

    public MyHandle createX(...) {
       MyHandle handle = new MyHandleImpl(); // create an implementation
       createdHandlers.add(handle); // add it to some structure (just a sample)
       return handle; // return the implementation. RMI will send to client a RMI reference to this very instance
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read various articles about the modal state that is used in the
I have read in various places that having variables with global scope, i.e. a
I've read in various books/articles that some Bindings, for example netTcpBinding and netMsmqBinding can
I have read in some books that the various graphics that make up UIKit
I've read through the various posts on SO about this, but have still not
I have read few articles about table partioning but still I am bit confused
I have just read this interesting article about the implementation details for various languages
I was reading some old articles about debugging, and one of them mentioned the
I have read various blogs about Serialization and the use of serialVersionUID. Most of
I have tried googling and read through https://help.github.com/en/articles/connecting-to-github-with-ssh and various, various guides. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.