Java Reference
In-Depth Information
2. Defi ne the implementation.
The code for the implementation class provides both a defi nition for the above
method and the defi nition for a constructor to set up the
ArrayList
s of
Account
objects:
import java.rmi.*;
import java.rmi.server.*;
import java.util.ArrayList;
public class Bank1Impl extends UnicastRemoteObject
implements Bank1
{
//Declare the ArrayList that will hold Account
//objects…
private ArrayList<Account> acctInfo;
//The constructor must be supplied with an ArrayList
//of
Account
objects…
public Bank1Impl(ArrayList<Account> acctVals)
throws RemoteException
{
acctInfo = acctVals;
}
//Defi nition for the single interface method…
public ArrayList<Account> getBankAccounts()
throws RemoteException
{
return acctInfo;
}
}
3. Create any required application classes.
In this example, there is only class
Account
to be defi ned. Since it is to be used in
the return value for our interface method, it must be declared to implement the
Serializable
interface (contained in package
java.io
).
public class Account implements java.io.Serializable
{
//Instance variables…
private int acctNum;
private String surname;
private String fi rstNames;
private double balance;
//Constructor…
public Account(int acctNo, String sname,
String fnames, double bal)
{
acctNum = acctNo;
Search WWH ::
Custom Search