Provide an Implementation for Each Remote Method

The implementation class for a remote object contains the code that implements each of the remote methods specified in the remote interface. For example, the following code is the implementation of the method that debits the purse:

    public short debit(short amount) throws RemoteException, UserException
        if (( amount < 0 )||( balance < amount )
            UserException.throwIt(REQUEST_FAILED);
        balance -= amount;
        return balance;	
   }

An operation is only allowed if the value of its parameter is compatible with the current state of the purse object. In this particular case, the application only checks that the amounts handled are positive and that the balance of the purse always remains positive.

In Java Card RMI, the arguments to and return values from remote methods are restricted. The main reason for this limitation is that the Java Card Platform, Version 3.1 does not support object serialization. The following are the rules for the Java Card Platform, Version 3.1:

  • The arguments to remote methods can be of any supported integral type (such as boolean, byte, short and int), or any single-dimensional arrays of these integral types.

    Note:

    The int type is optionally supported on the Java Card Platform, Version 3.1, so applications that use this type might not run on all platforms.

  • The return value from a remote method can be any type supported as arguments, as well as any remote interface type. The method can also return void.

On the other hand, object passing in Java Card RMI follows the normal RMI rules:

  • By default, non-remote objects are passed by copy, which means that all data members of an object are copied, except those marked static or transient. In the case of the Java Card Platform, Version 3.1, this rule is trivial to apply, because the only objects concerned are arrays of integral types.

  • Remote objects are passed by reference. In the case of the Java Card Platform, Version 3.1, remote objects can only be passed as return values. A reference to a remote object is actually a reference to a stub, which is a client-side proxy for the remote objects. Stubs are needed only when the format remote_ref_with_class is used for passing remote references. When another format, such as remote_ref_with_interfaces, is used, stubs are not necessary. Stubs are described in Generate the Stubs.

    Note:

    Even though the semantics of the Java Card Platform, Version 3.1 transient arrays are somewhat similar to transient fields in the Java programming language, different rules apply. The Java Card Platform, Version 3.1 contents are copied in Java Card RMI and passed by value when they are returned from a remote method.

A class can define methods not specified in a remote interface, but they can only be invoked on-card within the Java Card VM and cannot be invoked remotely.