ROM: Read only memory. Data are burned during card manufacture.
RAM: Random access memory
EEPROM: Electrically Erasable Programmable Read Only Memory
- Data stored in RAM are lost when power lost or JCSystem.CLEAR_ON_RESET or JCSystem.CLEAR_ON_DESELECT. But Data stored in EEPROM are preserved.
- The write operations to EEPROM are typically 1000 times slower than the write operations to RAM.
- The JavaCard memory model í motivated by the kind ò memory in smart cards and their physical characteristics. A typical JavaCard system places the JCRE code (JCVM, API,..) in ROM. Applet code can also be stored in ROM. RAM is used for temporary storage. The JavaCard runtime stack is allocated in RAM, intermefdiate results, method prarameters, local variables are put on the stack. Native methods, such as those performing cryptographic computations, alse save intermediate result in RAM. Longer-lived data are stored in EEPROM, as are dawnloaded applet calsses.
- A persistent object is created by the "new" operator.
- A persistent object holds states and values across CAD sessions.
- Any update to a single field in a persistent object is atomic. If the card loses power or a failure occurs during the update, the field is restored to its previous value.
- A persistent object can be referenced by a field in a transient object. If apersistent object is not referenced by other objects, it should be removed.
- A transient object is created by invoking the JavaCard APIs.
- A transient object does not hold states and values across CAD session.
- Any update to a single field in a transient object is not atomic.
- A transient object can be referenced by a field in a persistent object.
- A field in a transient object can be reference a persistent object.
- If a transient object is not referenced by other objects, it should be removed.
There are 2 type of transient objects, CLEAR_ON_RESET and CLEAR_ON_DESELECT.
- CLEAR_ON_RESET transient objects are used for maintaining data that need to be preserved acroos applet selections but not across card reset. Example "session key" field and .
- CLEAR_ON_DESELECT transient objects are used for maintaining data that must be preserved as long as an applet is selected, but not across applet selections or card resets. Example "session key" field.
Creating a transient object:
In JC tech, transient objects are created by using one of the factory methods in the JCSystem class:
public static boolean makeTransientBooleanArray(short length,
public static byte makeTransientByteArray(short length,
public static short makeTransientShortArray(short length,
public static Object makeTransientObjectArray(short length,
Example: create a transient bytes array with CLEAR_ON_DESELECT typebyte buffer = JCSystem.makeTransientByteArray((short) 100,