2.1.1Virtual Machine and Language Features
CldcComplete standardized descriptionJavaSome specifications of virtual machines and do not need to be supportedJavaLanguage Specification to define the features required by its virtual machine.SunThe company providesCldcStandard reference implementation. This implementation is based onCldcRequired Virtual MachineKVM. HoweverCldcThe device manufacturer does not have to be based onKVM. AnyCldcVirtual machines that have standardized features and can work in a restricted environment can be used. In this book, we provideKVMUnless explicitly stated, any of the features I mentioned also apply to any compatible virtual machines. In the following sections, we will introduceCldcUnsupported virtual machines and language features are different fromJ2se.
2.1.1.1floating POINT SUPPORT
Because manyCldcIf the platform does not have a hardware for floating-point operations, virtual machines do not need to support floating-point operations. For virtual machines2-1The bitcode operation is not implemented.
This introduces the following encoding restrictions:
ÜFloatAndDoubleVariables and arrays of these variables cannot be declared and used
ÜFloatAndDoubleType constants cannot be used
ÜThe method parameter cannot beFloatAndDoubleType
ÜObjectFloatAndDoubleCannot be created (in fact, these classes areCldcDoes not exist either.-Reference2.2Section)
SunNot specificallyCldcApplication provisionJavaCompiler, so you can useJ2seThe compiler creates a class file that uses floating point numbers, which violates the above rules. However, when loadedCldcWhen the virtual machine is strict, these class files will be rejected (refer2.1.2Section ).
2.1.1.2Lack of Language Features
Besides the limitations of floating point operationsJavaThe features of the language are as follows:CldcUnavailable in Application
Ing (Reflection)
Java. Lang. ReflectPackages and MappingsJava. Lang. ClassAll features are unavailable. This limit is partly applicable to memory storage, but it also saves the appCodeAre you authorized to access these features?
Weak reference (Weak references)
Because it needs to be stored for implementation, weak reference andJava. Lang. RefPackage not provided
Object end(Object finalization)
Compared with a small role,Object finalizationThis makes virtual machines very complex. So,Object finalizationNot implemented andCldcClassJava. Lang. ObjectNoFinalize ()Method
Thread features (Treading features)
CldcA thread is provided, but it does not allow the creation of a listening thread (when all non-listening threads of the Virtual Machine end, this thread is automatically terminated) and a thread group
Errors and exceptions (Errors and exceptions)
J2seA large number of classes are provided to handle errors and exceptions. BecauseJavaThe application usually does not want to recover from an error (meaning thatJava. Lang. Error), Most classes are not included inCldcPlatform. When such an error occurs, the device should take appropriate actions instead of reporting the error code. For details, refer2.2Section
JavaLocal interface(Java Native Interface)
CldcNot providedJ2se JNIFeature, which allowsJavaCode to call the local code.JNIIgnored This is partly because of memory consumption and ProtectionCldcTo avoid security issues caused by malicious code, see2.1.2Section.
2.1.1.3Class Loading
InJ2sePlatform and class loading are implemented through the class loader, including the application-defined class loader to implement an open mechanism for locating and LoadingJavaClass. On the contrary,CldcThe regulations require that the Implementation Department be covered and inherited by applications. The reason for this is to prevent the security problems caused by loading classes from trust.
CldcThe specification indicates that any virtual machine implementation must be able to loadJarCompressed application package. However, it does not develop additional methods that do not rely on devices to express and access application code, nor provide any methods for devices to locate and obtain code. These tasks are thrown to application management software that does not rely on devices, and their features are not within the scope of specifications.SunOfCldcA sample implementation that includes this function is calledJavaApplication Manager (Jam).
Devices can convert any supported extended format applications into more suitable and efficient internal formats. For examplePalmosOfMIDPProduct, includingCldcAnd acceptJarFormat, you can convert itPalmosSupportedPRCFormat. For more information, see9.2Section.