Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

Fundamentals of RMI

RMI Parameters

by jGuru

[Help | API Docs | Short Course| Exercises]


In this exercise you will create an RMI service that returns two objects to the client. As in SimpleBankingSyste m you need to change the constant HOST_NAME to match your computer's name on the network.

You will also extend the Hello interface and HelloImpl class to send a JavaTM object MessageObject from the server to the client.

While you are making these changes, take a careful look at MessageObject. It defines both a class variable and an object variable, which are both incremented each time the class is instantiated. By observing how these counters are incremented on the server and client side you can observe that RMI sends object instance information between JavaTM Virtual Machines1(JVMs), but not the static or class-level information.

The course material for this exercise is covered in Parameters in RMI.

Prerequisites

Skeleton Code

Tasks


  1. Add the getMessageObject method to the Hello interface.

  2. Create an implementation for the getMessageObject method in the HelloImpl class.

  3. Compile all of the class files for the server and its remote objects.

  4. Create the stub and skeleton files for the remote object implementation.

  5. Start the RMI Server in its own DOS console.

  6. Start the RMI Client in its own DOS console.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

TOP

Demonstration

When the server is run in its DOS console, the output will be:

Registry created on host computer <your_computer_name> on port 10002 Remote HelloService implementation object created Bindings Finished, waiting for client requests.

Then when the client is run in its DOS console, the output will be:

HelloService lookup successful The server says: Hello!

printing the message ("Hello!") you defined in your implementation object.

As your client runs both the server console and the client console it prints the instantiation messages from MessageObject. The server console displays:

MessageObject: Class Number is #0 Object Number is #0
MessageObject: Class Number is #1 Object Number is #1
MessageObject: Class Number is #2 Object Number is #2
MessageObject: Class Number is #3 Object Number is #3
MessageObject: Class Number is #4 Object Number is #4
MessageObject: Class Number is #5 Object Number is #5
MessageObject: Class Number is #6 Object Number is #6
MessageObject: Class Number is #7 Object Number is #7
MessageObject: Class Number is #8 Object Number is #8
MessageObject: Class Number is #9 Object Number is #9

While the client console displays:

MessageObject: Class Number is #0 Object Number is #0
MessageObject: Class Number is #0 Object Number is #1
MessageObject: Class Number is #0 Object Number is #2
MessageObject: Class Number is #0 Object Number is #3
MessageObject: Class Number is #0 Object Number is #4
MessageObject: Class Number is #0 Object Number is #5
MessageObject: Class Number is #0 Object Number is #6
MessageObject: Class Number is #0 Object Number is #7
MessageObject: Class Number is #0 Object Number is #8
MessageObject: Class Number is #0 Object Number is #9

Notice the difference in the class numbers.

While the MessageObject instance is moved between the server and the client, the two JVMs load their own, independent copies of the class file. The class variable is incremented on the server, but this is not reflected on the client side.

Next Magercise

Exercises

Short Course

Feedback

TOP

Copyright 1996-2000 jGuru.com. All Rights Reserved.

_______
1 As used on this web site, the terms "Java virtual machine" or "JVM" mean a virtual machine for the Java platform.


[ This page was updated: 25-Feb-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.