FileDocCategorySizeDatePackage
AccountClient.javaAPI DocExample1279Wed Apr 05 11:25:42 BST 2000None

AccountClient.java

/*
 * This example is from the book "Java Enterprise in a Nutshell".
 * Copyright (c) 1999 by O'Reilly & Associates.  
 * You may distribute this source code for non-commercial purposes only.
 * You may study, modify, and use this example for any purpose, as long as
 * this notice is retained.  Note that this example is provided "as is",
 * WITHOUT WARRANTY of any kind either expressed or implied.
 */

import java.rmi.Naming;
import java.rmi.RMISecurityManager;

/**
 * AccountClient: An example client for an RMI-export Account.
 *
 * Example pg. 45, Java Enterprise in a Nutshell, 1st ed.
 * Author: Jim Farley
 */

public class AccountClient {
  public static void main(String argv[]) {
    try {
      System.setSecurityManager(new RMISecurityManager());

      // Lookup account object
      Account jimAcct = (Account)Naming.lookup("rmi://192.168.0.1/JimF");

      // Make deposit
      jimAcct.deposit(12000);

      // Report results and balance.
      System.out.println("Deposited 12,000 into account owned by " +
                         jimAcct.getName());
      System.out.println("Balance now totals: " + jimAcct.getBalance());
    }
    catch (Exception e) {
      System.out.println("Error while looking up account:");
      e.printStackTrace();
    }
  }
}