Selecting the Java Card Applet and Obtaining the Initial Reference

To invoke methods on the remote objects of PurseApplet on the card, it must first be selected by using the AID as shown in the following code:

    // select the Java Card applet
    byte[] appAID = new byte[] {0x01,0x02,0x03,0x04,0x05,0x06,0x07, 0x08};
    jcRMI.selectApplet( appAID );

Then, the client must obtain the initial reference remote object for PurseApplet. JavaCardRMIConnect returns an instance of a stub class corresponding to the PurseImpl class on the card, which implements the Purse interface. The client application knows beforehand that the PurseApplet's initial remote reference implements the Purse interface and therefore casts it appropriately as shown in the following code:

// obtain the initial reference to the Purse interface
Purse myPurse = (Purse) jcRMI.getInitialReference();