Site Tools

Sidebar

Smart Card Solution

User Manual

JavaCard API Samples

Java Card Specification

Knowledge Sharing

javacard:jcvm:2.2.4.6_class_initialization

2.2.4.6 Class Initialization

The Java Card virtual machine contains limited support for class initialization because there is no general mechanism for executing methods. Support for methods is limited to the initialization of static field values with the following constraints:

  • Static fields of applet packages may only be initialized to primitive compile-time constant values, or arrays of primitive compile-time constants.
  • Static fields of user libraries may only be initialized to primitive compile-time constant values.
  • Only static fields declared in the current class may be initialized in the method.

Primitive constant data types include boolean, byte, short, and int.

Given Java technology source files that adhere to these language-level constraints on static field initialization, it is expected that reasonable Java compilers will:

  • Inline constants in the bytecodes that reference static final primitive fields that are initialized in the declaration statement.
  • Produce only the following bytecodes:
  • load a value on the stack: iconst_[m1,0-5], [b|s]ipush, ldc, ldc_w, aconst_null
  • create an array: newarray([byte|short|boolean|int] )
  • duplicate items on the stack: dup
  • store values in arrays or static fields: [b|i|s]astore, putstatic
  • return from method: return
javacard/jcvm/2.2.4.6_class_initialization.txt · Last modified: 2017/05/13 04:11 (external edit)