O'Reilly logo

Java Examples in a Nutshell, 3rd Edition by David Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Remote Banking

Example 21-1 shows a class, Bank, that contains inner classes and interfaces for a remote bank client/server example. In this example, the RemoteBank interface defines remote methods to open and close accounts, deposit and withdraw money, check the account balance, and obtain the transaction history for an account. The Bank class contains all of the classes and interfaces required for the example, except for the server class, which is the class that actually implements the RemoteBank interface. This server class is shown in Example 21-2.

Example 21-1 defines the following inner classes and interfaces:

RemoteBank

The Remote interface implemented by the bank server and used by the bank client.

FunnyMoney

A trivial class that represents money in this banking example. It is nothing more than a wrapper around an int, but it serves to demonstrate that Serializable objects can be passed as arguments to remote methods and returned by remote methods.

BankingException

A simple exception subclass that represents banking-related exceptions, such as "Insufficient funds." It demonstrates that remote method implementations on a server can throw exceptions that are transported across the network and thrown in the client program.

Client

This class is a standalone program that serves as a simple client to the bank server. It uses Naming.lookup( ) to look up the desired RemoteBank object in the system registry and then invokes various methods of that RemoteBank object, depending on its ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required