jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Confused about RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Confused about RMI" Watch "Confused about RMI" New topic

Confused about RMI

Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
Hello Ranchers:

I am really confused about the RMI stuff, after reading Roel De Nijs post when he states that he used generated stubs I got confused about this topic. First of all I read Andrew's book and he explains that we should use stubs and mentiones how to create them but I really don't know how to use them.

For instance I used his code to register the database object in RMI not using a factory only registerin the object extending UnicastRemoteObject and that's it. And to give it back to use it as a client I used the Naming.lookup method, but where is the stub getting involved what other steps do I need to do.

Reading a little more I found that you have to use the rmic tool so I went to command line used the rmic tool agains the object that implements the Remote interface and extends UnicastRemoteObject and... that was all, it generated a stub but what do I need to do with it... how do I use it?

I thought that I was near to completion of this assignment and now...

I hope you can help me on this.

SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCJD, SCEA in progress
Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
After generating the stub is there something else that I need to do ? or only following the code provided in Andrew's book would be the only needed ?
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2246

Howdy, Ulises!

Please take a look at this thread or this thread. I think it might be helpful! I can't really help you more than this because I myself didn't generate these stubs... but maybe my good buddy Roel (or someone else who did generate them) will show up later and give you a good explanation on this

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs

Joined: Jul 19, 2004
Posts: 4908

Hi Ulises,

Sorry that my post confused you, that was not my intention

But there is no need to be confused about this one. It is very easy:
- first decide if you want to generate stubs or not. if you decide to generate them, continue the reading (otherwise go have a )
- to generate them you can use the rmic command or you can use the ant task (as shown in this thread.
- after generating them you will see 2 extra class files NameOfYourRemoteClass_Skel.class and NameOfYourRemoteClass_Stub.class (you could also generate sources of these files with an extra option, but that's not needed for the assignment, but if you want to have a look what these classes do, you can do it that way).
- if you see those 2 classes in the runme.jar, your job is finished (and no dynamic code downloading will happen).

You won't see a thing about these stubs, because they are used in the background (just like the program works with jdk 1.5 or higher, even if you didn't generate them). I only generated my stubs when it was time to submit (not during development, just depending on the automagically generating of the stubs, built in jdk 1.5 or higher).

And as a final remark if you want to make sure your stubs are used, have a look at this thread.
if you call your program like this:

you will see when each class is loaded. The output to expect is shown in the last 3 post of that thread.

Hope you now have a clear picture about these stubs.
Kind regards,

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
Ok I got it, it was not that hard after all and no code changes needed to be done.

I did generated them using the command from Andrew book "rmic path.class" and I saw if they were used as the thread you sent me said and it seems they are being loaded so its ok by now. Well its time to wrap-up all and submit the file!

Thanks Roel, Roberto
Juergen Kessler

Joined: May 14, 2009
Posts: 1
I´m not sure about one thing. I decided to generate stubs but for which classes?
I use a factory, the interface is "DataFactory" and the implementation "DataFactoryImpl". Did I need stubs for both?
Thank you.
Roel De Nijs

Joined: Jul 19, 2004
Posts: 4908

Hi Juergen,

Welcome to the JavaRanch!

If you use my Ant-script to build your submission jar it will generate the stubs for you. Done by this line:

And the rmic tool is quiet smart: you just pass the directory with the classes and it knows which stubs he has to generate. You don't have to worry about it

Kind regards,
Marcelo Ruiz

Joined: Dec 19, 2007
Posts: 25
Hello Ranchers!

Roberto is right about the rmic task, but be aware that rmic ant task does a pretty lame job with processing JUnit test clases, specially inner classes. This will really annoy you if you use TDD (I try to do it most of the time) and want to have complete test cases for the client/server portion... otherwise it will create the stubs and skeletons for help you with no problem.

Ciao for now!

I agree. Here's the link: http://aspose.com/file-tools
subject: Confused about RMI
Similar Threads
Question regarding RMI
RMI Method Not Found!!!
rmic tool needed?
RMI with Java 5 (Stubs + Security)
some java interview Questions