Java Reference
In-Depth Information
{
try
{
//Obtain a reference to the object from the
//registry and typecast it into the appropriate
//type…
Bank1 temp = (Bank1)Naming.lookup(
"rmi://" + HOST + "/Accounts");
ArrayList<Account> acctDetails =
temp.getBankAccounts();
//Simply display all acct details…
for (int i=0; i<acctDetails.size(); i++)
{
//Retrieve an Account object from the
//ArrayList…
Account acct = acctDetails.get(i);
//Now invoke methods of Account object
//to display its details…
System.out.println("\nAccount number: "
+ acct.getAcctNum());
System.out.println("Name: "
+ acct.getName());
System.out.println("Balance: "
+ acct.getBalance());
}
}
catch(ConnectException conEx)
{
System.out.println(
"Unable to connect to server!");
System.exit(1);
}
catch(Exception ex)
{
ex.printStackTrace();
System.exit(1);
}
}
}
The steps for compilation and execution are the same as those outlined in the
previous section for the Hello example, with the minor addition of compiling the
source code for class Account . The steps are shown below.
Search WWH ::




Custom Search