...
1. Define the class that implements the remote interface and provide the implementation of the methods of this interface.
You can implement more than one remote interface in your implementation class.
2. You can also implement additional methods that are not defined by any of the implemented remote interfaces. However, such methods cannot be called remotely.
The AccountImpl class is the implementation class of the Account remote interface. The full code of the class is listed below:
package exapmles.rmi_p4;
import java.rmi.RemoteException;
public class AccountImpl implements Account { private int balance = 0;
public void deposit(int amount) throws RemoteException { if (amount < 0) { throw new RemoteException("Incorrect value:" + amount); } balance += amount; }
public void draw(int amount) throws OverdrawException { if (balance < amount) { throw new OverdrawException(amount - balance ); } balance -= amount; }
public int getBalance() { return balance; } } |