What is preverification? Why do I receive error messages from the CLDC/KVM when I do not preverify my class files?

Bill Day

Preverification is a new phase in the development and deployment cycle for Java applications designed to run on the J2ME CLDC.

Preverification performs certain checks on the Java bytecodes ahead of runtime. If this first verification pass is ok, the preverifier annotates the classfiles (using standard Java bytecode "attributes", so that these are still plain old Java bytecodes and will be executable in VMs not aware of the benefits of preverification), and then saves the annotated class files or passes them along to the next tool in the compile chain.

When the KVM attempts to run execute a J2ME CLDC-based application, it checks the Java class files for these preverification annotations. Proper annotations in the class files guarantee that certain compile-time checks were made, and so the KVM can pass through its own verfication and security checks much faster and start executing the application more quickly.

Sun's CLDC reference implementation SDK includes the 'preverify' tool. You use the tool after compiling your code via javac (or your favorite Java compiler). More information on preverify is included in the CLDC specification and in the developer docs included with the CLDC SDK.