Main Program

As for any Java Card RMI program, the first step is to define the interface to be used as contract between the server (the Java Card technology-based application) and its clients (the terminal applications):

package examples.purse;
import java.rmi.*;
import javacard.framework.*;
public interface Purse extends Remote {
    public static final short MAX_AMOUNT = 400;
    public static final short REQUEST_FAILED = 0x0102;
    public short debit(short amount) throws RemoteException, UserException;
    public short credit(short amount) throws RemoteException,
    UserException;
    public short getBalance() throws RemoteException, UserException;
}


This is a typical Java Card RMI interface in the following ways:

  • The interface type extends the java.rmi.Remote interface. This interface is a tagging interface that identifies the interface as defining a remotely accessible object.

  • Every method in the interface must be declared as throwing a RemoteException or one of its superclasses (IOException or Exception). This exception is required to encapsulate all the communication problems that might occur during a remote invocation of the method. In addition, the credit, debit, and getBalance methods also throw the UserException to indicate application-specific errors.

  • The interface can also define values for constants that might be used in communication between the client and the server. The Purse interface defines a constant MAX_AMOUNT that represents the maximum allowed value for the transaction amount parameter. It also defines a reason code REQUEST_FAILED for the UserException qualifier.