Utility Sample

The Utility sample demonstrates how you can use the utility APIs in an application. This applet is a simple version of a hypothetical broker applet that is used to assist the user in buying and selling stocks. The applet uses constructed TLVs and primitive TLVs to manage the portfolio. The communication with the broker is also in the form of TLVs and uses the math API to determine the value of a trade. It also uses the integer API to construct an integer from byte array and set integers in byte arrays for TLV objects.

This applet provides the following features:

  • PIN Protection - PIN protected access to the application. Uses the standard PIN API in the Java Card platform to protect access to the applet.

  • Storage of Portfolio - Storage of portfolio information on the card. The applet uses a portfolio constructed TLV to store the information regarding all the stocks that the user currently holds. The information is stored in the form of stockInfo constructed TLV. Each stockInfo TLV contains the following:

    • Stock symbol

    • Number of stocks

    • Last Trade Constructed TLV

    • Number of stocks

    • Stock Price

  • Stock Trading - The applet assists the user in buying and selling stocks by creating a "signed" purchasing or selling request for the broker in the form of a stock purchase request constructed TLV or sell stock request constructed TLV. Before the request is generated, the applet checks to see if the user has enough stocks in case the request is to sell the stock and enough account balance if the request is to buy new stock. The request is sent back to the terminal where the terminal application may retrieve the TLV from the response APDU and send it to the broker.

    If the trade is successful, the broker sends back a confirmation message in the form of a sell confirmation TLV or purchase confirmation TLV. The applet retrieves the information from the confirmation TLV and updates the portfolio as follows:

    • If a new stock is bought, the applet creates a new constructed stockInfo TLV to store the new stock information.

    • If the user already had a stock, the number of stocks the user currently holds, and the last trade information is updated accordingly.

    • If the user, because of the trade, has 0 stocks of a certain company, the stockInfo TLV for that stock is removed from the portfolio constructed TLV.

  • Retrieval of complete portfolio information from the card.

  • Get Information On a Stock - Retrieval of information on a particular stock in the portfolio. User may use this feature to get information regarding a specific stock rather than retrieving the whole portfolio. If a stock is not found, the appropriate exception is thrown. The information is returned in the form of a stockInfo TLV that contains the following:

    • Stock symbol

    • Number of stocks

    • Last trade constructed TLV

    • Number of stocks

    • Stock price

  • Assistance for the user in creating a stock purchase request for the broker.

  • Assistance the user in creating a sell stock request for the broker.

  • On receiving a trade confirmation, update the portfolio accordingly.

  • Get information on current user account balance.

Follow one of these sets of instructions to run this sample: