2Objects in the Java Card JCRE and applets create objects to represent, store and manipulate dataObject in in the Java Card:All the objects on the Java Card platform are instances of classes or array types, which have the same root class java.lang.Object.Fields in a new object or components in a new array are set to their default values (zero, null, or false) unless they are initialized to some other values in the constructor.
3Java Card Memory Model Three kinds of memory: ROM, RAM, and EEPROM. read only memory where program and data were burned.The least expensiveRAM and EEPROM can be read and written.RAM is used for temporary storage; EEPROM is used for longer-lived data.
4Persistent Objects (Ⅰ) A persistent object is created by the new operator.A persistent object holds states and values across CAD sessions.Any update to single field in a persistent object is atomic.A persistent object can be referenced by a field in a transient object.A field in a persistent object can reference a transient object.
5Persistent Objects (Ⅱ) If a persistent object is not referenced by other objects, it becomes unreachable or can be garbage collected.
6Transient Object The term transient object is somewhat of misnomer. It can be incorrectly interpreted to mean that the object itself is temporary: when the power is removed, the transient object is destroyedIn fact, the term transient object means that the contents of the fields of the object have a temporary natureAs with persistent objects, the space allocated for transient objects is reserved and cannot be reclaimed unless a garbage collector is implemented.
7Transient ObjectAn applet should create a transient object only once during its lifetime and should save the object reference in a persistent field (see Figure 4.1 on page 51)The next time the card is powered on, the applet use the same object reference to access the transient object (variable)
8Transient objectsIn Java Card 2.1, only arrays with primitive types or arrays with references to Object can be declared transientThe primitive type in Java Card platform are byte, short, int and booleanTransient object == transient array
9Properties of transient objects(Ⅰ) A transient object is created by invoking the Java Card APIs.A transient object does not hold states and values across CAD sessions. The fields of a transient object are cleared to their default value (zero,false, or null) at the occurrence of certain events.Any update to a single field in a transient object is not atomic.
10Properties of Transient Objects (Ⅱ) A transient object can be referenced by a field in persistent objects.A field in a transient object can reference a persistent object.If a transient object is not referenced by other objects, it becomes unreachable or can be garbage collected.Writes to the fields of a transient object do not have a performance penalty, because RAM has a much faster write cycle time than EEPROM
11Transient Object Types CLEAR_ON_RESET Transient objects are used for maintaining data that need to be preserved across applet selections but not across card resets.Card master session keyCLEAR_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.Applet-owned session key
12Creating Transient Objects In Java Card technology, transient objects are created by using one of the factory methods in the JCSystem class.Table 4.1 on page 53public static boolean makeTransientBooleanArray(short length, byte event)makeTransientByteArraymakeTransientShortArraymakeTransientObjectArray
13Creating Transient Objects Length specifies the requested transient array lengthEvent indicates which kind of event clear the object (CLEAR_ON_RESET and CLEAR_ON_DESELECT)Example:byte buffer = JCSystem.makeTransientByteArray(BUFFER_LENGTH, JCSystem.CLEAR_ON_DESELECT)
14Querying Transient Objects An applet may need to access an object that is created by different applet.JCSystem class provides a convenient query method for an applet to determine whether an object being accessed is transientpublic static byte isTransient(Object theObject)The method isTansient returns a constant (either CLEAR_ON_RESET or CLEAR_ON_DESELECT) or the constant JCSystem.NOT_A_TRANSIENT_OBJECT to indicate that the object is null or is a persistent object.
15A Few Words about Objects Creation and Deletion If there isn’t sufficient nonvolatile space available when an applet tries to create a persistent object using the new operator, the JCRE will throw a SystemException with the reason code JCSystem.NO_RESOURCE.When an applet calls one of the make-transient-object and there is insuffient RAM space available, JCRE throws a SystemException with the reason code JCSystem.NO_TRANSIENT_SPACE