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
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
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 ).
public class Account implements
//Instance variables…
private int acctNum;
private String surname;
private String fi rstNames;
private double balance;
public Account(int acctNo, String sname,
String fnames, double bal)
acctNum = acctNo;
Search WWH ::

Custom Search