I'm new on Java Card applications. At this moment I would like to store a hash table (dictionary) that contains the configuration of a terminal that reads this type of cards. If the hash table has values, those must be retrieved to the terminal (I think using APDU's right?) but also if there are no values, the terminal must create a "default" initial configuration.
Is it possible to do this? If it is, how? Maybe there is an applet ready for that (like Musclecard for key generation and signing) but I haven't found any.
Any advice? Thanks!
Java Card is pretty limited regarding support for data structures. It has a few basic types such as byte
and short
and optionally int
, which is not used anywhere in the classic API. For those types you can generate two types of transient (RAM) arrays using JCSystem.makeTransientByteArray()
and friends. Furthermore, the default byte[]
, short[]
and Object[]
created using new
are stored in EEPROM.
The Object
class in Java Card has been stripped down as well. This means that there is no such thing as hashCode()
. If it was present then you would run into problems as the Java SE version of hashCode()
returns an integer, which is probably not present. All defined data containers are either smart card or security related (e.g. the APDU
and Key
classes).
So basically, if you want to create a HashMap
- the common type of dictionary on Java SE - then you will have to create it yourself. It is in that case a good idea to define a Hashable
interface that classes can implement to act as a key. The structures should be generated in the right type of memory. For the kind of application you specify you probably need persistent memory, which is kind of the default for object instances created using the new
key word.
Personally, I would make very sure you need a hashCode()
method for your solution. It is probably easier to create an Object array and simply iterate over the elements.