站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Programming Wireless Devices with the Java2 Platform

Programming Wireless Devices with the Java2 Platform

[ directory ] Previous Section Next Section

4.3 Java Language Specification Compatibility

The general goal for a virtual machine conforming to CLDC is to be as compliant with the JavaLanguage Specification as is feasible within the strict memory limits of CLDC target devices. This section summarizes the differences between a virtual machine conforming to CLDC and the Java Virtual Machine of Java 2 Standard Edition (J2SE). Except for the differences indicated herein, a virtual machine conforming to CLDC is compatible with The Java™ Language Specification, Second Edition, by James Gosling, Bill Joy, Guy L. Steele, and Gilad Bracha, Addison-Wesley, 2000, ISBN 0-201-31008-2.

Note

For the remainder of this book, the Java™ Language Specification is referred to as JLS. Sections within the Java™Language Specification are referred to using the § symbol. For example, (JLS §4.2.4).


4.3.1 No Finalization of Class Instances

CLDC libraries do not include the method java.lang.Object.finalize(). Therefore, a virtual machine conforming to CLDC does not support finalization of class instances (JLS §12.6). No application built to conform to the Connected, Limited Device Configuration can require that finalization be available.

4.3.2 Error-Handling Limitations

A virtual machine conforming to CLDC generally supports exception handling as defined in JLS Chapter 11, with the exception that asynchronous exceptions (JLS §11.3.2) are not supported.

In contrast, the set of error classes included in CLDC libraries is limited, and consequently the error-handling capabilities of CLDC are considerably more limited. This is because of two reasons:

  1. In embedded systems, recovery from error conditions is usually highly device-specific. Application programmers cannot be expected to know about device-specific error-handling mechanisms and conventions.

  2. As specified in JLS §11.5, class java.lang.Error and its subclasses are exceptions from which programs are not ordinarily expected to recover. Implementing the error-handling capabilities fully according to the Java™ Language Specification is rather expensive, and mandating the presence and handling of all the error classes would impose an overhead on the virtual machine implementation.

A virtual machine conforming to CLDC provides a limited set of error classes defined in Section 5.2.7, "Exception and Error Classes." When encountering any other error, the implementation behaves as follows:

  • either the virtual machine halts in an implementation-specific manner,

  • or the virtual machine throws an Error that is the nearest CLDC-supported superclass of the Error class that must be thrown according to the Java™ Language Specification.

If the virtual machine conforming to CLDC implements additional error checks that are part of the Java™ Language Specification but that are not required by the CLDC Specification, the implementation shall throw the nearest CLDC-supported superclass of the Error class that is defined by the Java™ Language Specification.

    [ directory ] Previous Section Next Section