vico
vico

Reputation: 18201

Debug info to console

I'm developing applet in JCIDE. Sometimes I need to make output to debug window. How to achieve this? In Java we have:

System.out.println("Hello, world.");

I see some debug information that I suppose come from libraries: enter image description here

Upvotes: 1

Views: 143

Answers (1)

Maarten Bodewes
Maarten Bodewes

Reputation: 94038

There are of course multiple ways to achieve this.

Assuming that you mean to debug by printing thing out, the best way is probably to create a buffer (transient or persistent) and create a separate APDU command to read out that buffer. Then on the terminal you only need some code to to call the command and decode the response from binary to text. Generally I would not bother with strings, but I would for instance put in variable values. Do make sure you test your final delivery though; the command should be removed from the code before you release it.

If you just want to debug you could also try to see if (part of) your product can run in e.g. jCardSIM. The advantage of that is that you may not need to remove the annoying debug code as the values can simply be seen in the variables.

Beware that Java Card doesn't contain a String definition and can, of course, not handle "String literals" either. You can however create byte arrays using the character notation as the compiler is smart enough to perform the conversion. So the following does work: byte[] hi = {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 't'}. And yes, that last 't' in there is going to follow you till the end of days. Beware though that this will create an array in persistent memory, so probably not a good idea to call the code multiple times (i.e. make it a constant, field or whatever).

Upvotes: 2

Related Questions