//applet必须要属于package
package samples.HelloWorld;
import javacard.framework.*; //imoprt必要的package
public class HelloWorld extends Applet
{
//此echoBytes array为"HelloWorld"的16进位表示法
private static final byte echoBytes[] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x57, 0x6f, 0x72, 0x6c, 0x64};
//applet constructor
public HelloWorld(APDU apdu)
{
//在applet initiate时向JCRE注册
register();
}
//当applet下载至Java Card时,则会启动install method来安装applet,并传入applet install所要的参数
public static void install( byte[] bArray, short bOffset, byte bLength )
{
//安装
HelloWorld applets new HelloWorld(null);
}
public void process(APDU apdu) throws ISOException
{
//处理terminal端的APDU指令
byte buffer[] = apdu.getBuffer();
//取得APDU之buffer
//将echoBytes,及"HelloWorld"byte自串copy至APDU的buffer
Util.arrayCopyNonAtomic(echoBytes, (short)0, buffer,(short)0, (short)echoBytes.length);
//将APDU buffer的资料设为"写出",并直接传送出去
apdu.setOutgoingAndSend((short)0, (short)echoBytes.length);
}
}