JavaCard Wiki
A Java Card knowledge base in its early days — get the smallest applet working first, then grow around it.
This site is just getting started; this is currently the only page. It aims to make the smallest working loop clear: write an applet, install it on a card, send one APDU, and read the response. Environment setup, APDU details, and status-word troubleshooting can come later, when they are actually needed.
The smallest applet
Section titled “The smallest applet”An applet that does exactly one thing: it returns Hello World when INS = 0x01 and 6D00 for anything else.
package com.example.hello;
import javacard.framework.APDU;import javacard.framework.Applet;import javacard.framework.ISO7816;import javacard.framework.ISOException;
public class HelloWorldApplet extends Applet {
private static final byte[] HELLO = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', };
public static void install(byte[] bArray, short bOffset, byte bLength) { new HelloWorldApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]); }
public void process(APDU apdu) { if (selectingApplet()) { return; }
byte[] buffer = apdu.getBuffer(); if (buffer[ISO7816.OFFSET_INS] != (byte) 0x01) { ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); }
for (short i = 0; i < HELLO.length; i++) { buffer[i] = HELLO[i]; } apdu.setOutgoingAndSend((short) 0, (short) HELLO.length); }}Calling it
Section titled “Calling it”Assuming the applet’s AID is F0 00 00 00 01:
| Step | APDU | Expected |
|---|---|---|
| Select the applet | 00 A4 04 00 05 F0 00 00 00 01 |
9000 |
| Invoke the command | 00 01 00 00 00 |
48 65 6C 6C 6F 20 57 6F 72 6C 64 90 00 |
The trailing 9000 is a status word meaning success; 6D00 means the card does not support that INS.