📄 jcvm02lang.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML LANG="en"><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><META NAME="GENERATOR" CONTENT="Adobe FrameMaker 7.0/HTML Export Filter"><LINK REL="STYLESHEET" HREF="unx_unstr_styles.css" CHARSET="ISO-8859-1" TYPE="text/css"><META name="DC.TITLE" content="Virtual Machine Specification, Java Card Platform, v2.2.2"><TITLE>C H A P T E R 2 - A Subset of the Java Virtual Machine </TITLE></HEAD><BODY BGCOLOR="#ffffff"><DIV><div class="navbar" align="center"><table dir="LTR" summary="Navigation bar, includes the book title and navigation buttons" width=100% cellpadding="0" cellspacing="0" border="0"><colgroup span="2" width="100%"><col id="1" span="1" width="50%"><col id="2" span="1" width="50%"><tr bgcolor="#cccccc"><td class="navbartitle" align=left rowspan="1" colspan="1" abbr="ChapTitle"> Virtual Machine Specification, Java Card Platform, v2.2.2</td><td valign="top" align="right" rowspan="1" colspan="1" abbr="NavButtons"><a href="index.html"><img src="shared/toc01.gif" title="Table Of Contents" alt="Table Of Contents" width="30" height="26" border="0"></a><a href="JCVM01intro.html"><img src="shared/prev01.gif" title="Previous Chapter" alt="Previous Chapter" width="30" height="26" border="0"></a><a href="JCVM03structVM.html"><img src="shared/next01.gif" title="Next Chapter" alt="Next Chapter" width="30" height="26" border="0"></a><a href="ix.html"><img src="shared/index01.gif" title="Book Index" alt="Book Index" width="30" height="26" border="0"></a></td></tr></table><br><br></div></DIV><TABLE DIR="LTR" SUMMARY="Chapter Number" ABBR="ChapNum" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1"><TR><TD ALIGN="right" CLASS="ChapNumber"><SPAN CLASS="ChapNumPrefix"><A NAME="pgfId-35832"></A>C H A P T E R </SPAN> <SPAN CLASS="ChapNumNum">2</SPAN><A NAME="45905"></A></TD></TR></TABLE><TABLE DIR="LTR" SUMMARY="Chapter Title" ABBR="ChapTitle" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1" WIDTH="100%"><TR><TD ALIGN="right" CLASS="ChapTitle"><HR SIZE=7 NOSHADE><A NAME="pgfId-35833"></A><A NAME="25177"></A>A Subset of the Java Virtual Machine</TD></TR></TABLE><P CLASS="Paragraph"><A NAME="pgfId-35834"></A>This chapter describes the subset of the <A NAME="marker-47333"></A>Java virtual machine and language that is supported in the Java Card platform, Version 2.2.2. </P><H2 CLASS="Head1"><A NAME="pgfId-35835"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>2.1 Why a Subset is Needed</H2><P CLASS="Paragraph"><A NAME="pgfId-35836"></A>It would be ideal if programs for smart cards could be written using all of the <A NAME="marker-47334"></A>Java programming language, but a full implementation of the Java virtual machine is far too large to fit on even the most advanced resource-constrained devices available today.</P><P CLASS="Paragraph"><A NAME="pgfId-35837"></A>A typical resource-constrained device has on the order of 1.2K of RAM, 16K of non-volatile memory (EEPROM or flash) and 32K-48K of ROM. The code for implementing string manipulation, single and double-precision floating point arithmetic, and thread management would be larger than the ROM space on such a device. Even if it could be made to fit, there would be no space left over for class libraries or application code. RAM resources are also very limited. The only workable option is to implement Java Card technology as a subset of the Java platform. </P><H2 CLASS="Head1"><A NAME="pgfId-35838"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>2.2 Java Card Platform Language Subset</H2><P CLASS="Paragraph"><A NAME="pgfId-35839"></A>Applets written for the Java Card platform are written in the Java programming language. They are compiled using Java compilers. Java Card technology uses a subset of the Java language, and familiarity with the Java platform is required to understand the Java Card platform. </P><P CLASS="Paragraph"><A NAME="pgfId-35840"></A>The items discussed in this section are not described to the level of a language specification. For complete documentation on the Java programming language, see <I CLASS="Title">The Java Language Specification</I>. </P><H3 CLASS="Head2"><A NAME="pgfId-35841"></A>2.2.1 Unsupported Items</H3><P CLASS="Paragraph"><A NAME="pgfId-35842"></A>The items listed in this section are elements of the Java programming language and platform that are not supported by the Java Card platform.</P><H4 CLASS="Head3"><A NAME="pgfId-35843"></A>2.2.1.1 <A NAME="23587"></A>Unsupported <A NAME="marker-47343"></A>Features</H4><H5 CLASS="Head4"><A NAME="pgfId-35844"></A><A NAME="marker-47344"></A>Dynamic Class Loading</H5><P CLASS="Paragraph"><A NAME="pgfId-35845"></A>Dynamic class loading is not supported in the Java Card platform. An implementation of the Java Card platform is not able to load classes dynamically. Classes are either masked into the card during manufacturing or downloaded through an installation process after the card has been issued. Programs executing on the card may only refer to classes that already exist on the card, since there is no way to download classes during the normal execution of application code.</P><H5 CLASS="Head4"><A NAME="pgfId-35846"></A><A NAME="marker-47345"></A>Security Manager</H5><P CLASS="Paragraph"><A NAME="pgfId-35847"></A>Security management in the Java Card platform differs significantly from that of the Java platform. In the Java platform, there is a Security Manager class (<KBD CLASS="Filename-Command">java.lang.SecurityManager</KBD>) responsible for implementing security features. In the Java Card platform, language security policies are implemented by the virtual machine. There is no Security Manager class that makes policy decisions on whether to allow operations.</P><H5 CLASS="Head4"><A NAME="pgfId-46595"></A><A NAME="Garbage Collection & Finalization"></A>Finalization<A NAME="marker-47346"></A></H5><P CLASS="Paragraph"><A NAME="pgfId-35850"></A>Finalization is also not supported. <KBD CLASS="Filename-Command">finalize()</KBD> will not be called automatically by the Java Card virtual machine.</P><H5 CLASS="Head4"><A NAME="pgfId-38875"></A><A NAME="marker-47347"></A>Threads</H5><P CLASS="Paragraph"><A NAME="pgfId-38876"></A>The Java Card virtual machine does not support multiple threads of control. Programs for the Java Card platform ("Java Card programs") cannot use class <KBD CLASS="Filename-Command">Thread</KBD> or any of the thread-related keywords in the Java programming language.</P><H5 CLASS="Head4"><A NAME="pgfId-35853"></A><A NAME="marker-47348"></A>Cloning</H5><P CLASS="Paragraph"><A NAME="pgfId-35854"></A>The Java Card platform does not support cloning of objects. Java Card API class <KBD CLASS="Filename-Command">Object</KBD> does not implement a <KBD CLASS="Filename-Command">clone</KBD> method, and there is no <KBD CLASS="Filename-Command">Cloneable</KBD> interface provided.</P><H5 CLASS="Head4"><A NAME="pgfId-35855"></A><A NAME="Access Control in Java Packages"></A>Access <A NAME="marker-47349"></A>Control in Java Packages</H5><P CLASS="Paragraph"><A NAME="pgfId-35856"></A>The Java Card platform language subset supports the package access control defined in the Java language. However, the cases that are not supported are as follows.</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-35857"></A>If a class implements a method with package access visibility, a subclass cannot override the method and change the access visibility of the method to protected or public.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-46661"></A>A public class cannot contain a public or protected field of type reference to a package-visible class. </LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-46735"></A>A public class cannot contain a public or protected method with a return type of type reference to a package-visible class.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-43986"></A>A public or protected method in a public class cannot contain a formal parameter of type reference to a package-visible class.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-43994"></A>A package-visible class that is extended by a public class cannot define any public or protected methods or fields.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-46447"></A>A package-visible interface that is implemented by a public class cannot define any fields.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-46640"></A>A package-visible interface cannot be extended by an interface with public access visibility.</LI><P CLASS="Linebreak"></P></UL><H5 CLASS="Head4"><A NAME="pgfId-51811"></A>Typesafe Enums</H5><P CLASS="Paragraph"><A NAME="pgfId-51727"></A>The Java Card platform language subset does not support the enumerated type facility and the keyword enum. </P><H5 CLASS="Head4"><A NAME="pgfId-52130"></A>Enhanced for Loop</H5><P CLASS="Paragraph"><A NAME="pgfId-52128"></A>The Java Card platform language subset does not support the enhanced for loop language construct. Support for the enhanced for loop construct requires support for array indexing using the integer data type. The Java Card platform only supports array indexing using the short data type.</P><H5 CLASS="Head4"><A NAME="pgfId-51728"></A>Varargs</H5><P CLASS="Paragraph"><A NAME="pgfId-51863"></A>The Java Card platform language subset does not support variable-length argument lists. The variable-length argument construct requires the compiler to generate code that creates a new array object each time a variable-length argument array method is invoked, thereby causing implicit memory allocations in Java Card runtime memory heap.</P><H5 CLASS="Head4"><A NAME="pgfId-51779"></A>Runtime Visible Metadata (Annotations)</H5><P CLASS="Paragraph"><A NAME="pgfId-51775"></A>The Java Card platform does not support this language feature which lets you introduce meta-data information into the runtime environment to be accessed reflectively. The Java Card platform does not support reflection.</P><H5 CLASS="Head4"><A NAME="pgfId-51923"></A>Assertions</H5><P CLASS="Paragraph"><A NAME="pgfId-51924"></A>The Java Card runtime does not provide runtime support for statements in the Java programming language called assertions that are used to test assumptions about program functionality. </P><H4 CLASS="Head3"><A NAME="pgfId-35859"></A>2.2.1.2 <A NAME="marker-47350"></A>Keywords</H4><P CLASS="Paragraph"><A NAME="pgfId-35860"></A>The following keywords indicate unsupported options related to native methods, threads, floating point, memory management, and debugging.</P><BR><TABLE CLASS="Titled" BORDER=1 BORDERCOLORLIGHT="#FFFFFF" BORDERCOLORDARK="#000000" CELLPADDING=5 CELLSPACING=0 DIR="LTR"><CAPTION CLASS="TableCaption"><A NAME="pgfId-49057"> </A> TABLE 2-1 Unsupported Keywords </CAPTION><TBODY><TR><TD SCOPE="ROW" ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-39401"></A><KBD CLASS="Filename-Command">native</KBD><A NAME="marker-47357"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-39403"></A><KBD CLASS="Filename-Command">synchronized</KBD><A NAME="marker-47358"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-39405"></A><KBD CLASS="Filename-Command">transient</KBD><A NAME="marker-47360"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-39407"></A><KBD CLASS="Filename-Command">volatile</KBD><A NAME="marker-47361"></A></P></TD></TR><TR><TD SCOPE="ROW" ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-46471"></A><KBD CLASS="Filename-Command">strictfp</KBD><A NAME="marker-47359"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-46473"></A><KBD CLASS="Filename-Command">enum</KBD></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-46475"></A><KBD CLASS="Filename-Command">assert</KBD></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-46477"></A> </P></TD></TR></TBODY></TABLE><BR><H4 CLASS="Head3"><A NAME="pgfId-35868"></A>2.2.1.3 Unsupported <A NAME="marker-47351"></A>Types</H4><P CLASS="Paragraph"><A NAME="pgfId-35869"></A>The Java Card platform does not support types <KBD CLASS="Filename-Command">char</KBD><A NAME="marker-47353"></A>, <KBD CLASS="Filename-Command">double</KBD><A NAME="marker-47354"></A>, <KBD CLASS="Filename-Command">float</KBD><A NAME="marker-47355"></A> and <KBD CLASS="Filename-Command">long</KBD><A NAME="marker-47356"></A>. It also does not support arrays of more than one dimension.</P><H4 CLASS="Head3"><A NAME="pgfId-35870"></A>2.2.1.4 <A NAME="marker-47352"></A>Classes</H4><P CLASS="Paragraph"><A NAME="pgfId-35871"></A>In general, none of the Java programming language core API classes are supported in the Java Card platform. Some classes from the <KBD CLASS="Filename-Command">java.lang</KBD> package are supported (see <A HREF="JCVM02lang.html#Classes" CLASS="XRef">Section 2.2.2.4, Classes</A>), but none of the rest are. For example, classes that are not supported are <KBD CLASS="Filename-Command">String</KBD>, <KBD CLASS="Filename-Command">Thread</KBD> (and all thread-related classes), wrapper classes such as <KBD CLASS="Filename-Command">Boolean</KBD> and <KBD CLASS="Filename-Command">Integer</KBD>, and class <KBD CLASS="Filename-Command">Class</KBD>.</P><H5 CLASS="Head4"><A NAME="pgfId-35875"></A><A NAME="marker-47362"></A>System<A NAME="marker-47363"></A></H5><P CLASS="Paragraph"><A NAME="pgfId-35876"></A>Class <KBD CLASS="Filename-Command">java.lang.System</KBD> is not supported. Java Card technology supplies a class <KBD CLASS="Filename-Command">javacard.framework.JCSystem</KBD>, which provides an interface to system behavior.</P><H3 CLASS="Head2"><A NAME="pgfId-35877"></A>2.2.2 Supported Items</H3><P CLASS="Paragraph"><A NAME="pgfId-35878"></A>If a language feature is not explicitly described as unsupported, it is part of the supported subset. Notable supported features are described in this section.</P><H4 CLASS="Head3"><A NAME="pgfId-35879"></A>2.2.2.1 Features</H4><H5 CLASS="Head4"><A NAME="pgfId-38898"></A><A NAME="marker-47364"></A>Packages</H5><P CLASS="Paragraph"><A NAME="pgfId-38899"></A>Software written for the Java Card platform follows the standard rules for the Java platform packages. Java Card API classes are written as Java source files, which include package designations. Package mechanisms are used to identify and control access to classes, static fields and static methods. Except as noted in "Access Control in Java Packages" (<A HREF="JCVM02lang.html#23587" CLASS="XRef">Section 2.2.1.1, Unsupported Features</A>), packages in the Java Card platform are used exactly the way they are in the Java platform.</P><H5 CLASS="Head4"><A NAME="pgfId-35885"></A><STRONG>Dynamic Object Creation</STRONG><A NAME="marker-47365"></A></H5><P CLASS="Paragraph"><A NAME="pgfId-43416"></A>The Java Card platform programs supports dynamically created objects, both class instances and arrays. This is done, as usual, by using the <KBD CLASS="Filename-Command">new</KBD> operator. Objects are allocated out of the heap.</P><P CLASS="Paragraph"><A NAME="pgfId-43420"></A>A Java Card virtual machine will not necessarily garbage collect objects. Any object allocated by a virtual machine may continue to exist and consume resources even after it becomes unreachable. See <A HREF="JCVM02lang.html#40841" CLASS="XRef">Section 2.2.3.2, Object Deletion Mechanism</A> for more information regarding support for an optional object deletion mechanism.</P><H5 CLASS="Head4"><A NAME="pgfId-35891"></A><A NAME="marker-47366"></A>Virtual Methods</H5><P CLASS="Paragraph"><A NAME="pgfId-35892"></A>Since Java Card technology-based objects ("Java Card objects") are Java programming language objects, invoking virtual methods on objects in a program written for the Java Card platform is exactly the same as in a program written for the Java platform. Inheritance is supported, including the use of the <KBD CLASS="Filename-Command">super</KBD> keyword.</P><H5 CLASS="Head4"><A NAME="pgfId-52553"></A>Interfaces</H5><P CLASS="Paragraph"><A NAME="pgfId-38918"></A>Java Card API classes may define or implement interfaces as in the Java programming language. Invoking methods on interface types works as expected. Type checking and the <KBD CLASS="Filename-Command">instanceof</KBD> operator also work correctly with interfaces.</P><H5 CLASS="Head4"><A NAME="pgfId-35895"></A><A NAME="marker-47368"></A>Exceptions</H5><P CLASS="Paragraph"><A NAME="pgfId-37107"></A>Java Card programs may define, throw and catch exceptions, as in Java programs. Class <KBD CLASS="Filename-Command">Throwable</KBD> and its relevant subclasses are supported. Some <KBD CLASS="Filename-Command">Exception</KBD> and <KBD CLASS="Filename-Command">Error</KBD> subclasses are omitted, since those exceptions cannot occur in the Java Card platform. See <A HREF="JCVM02lang.html#Exceptions" CLASS="XRef">Section 2.3.3, Exceptions</A> for specification of errors and exceptions.</P><H5 CLASS="Head4"><A NAME="pgfId-51748"></A>Generics</H5><P CLASS="Paragraph"><A NAME="pgfId-51789"></A>This Java language facility allows a type or method to operate on objects of various types while providing compile-time type safety. It adds compile-time type safety and eliminates the need for casting. </P><H5 CLASS="Head4"><A NAME="pgfId-51880"></A>Static Import</H5><P CLASS="Paragraph"><A NAME="pgfId-51877"></A>This Java language facility lets you avoid importing an entire class simply to access its static members or qualifying static members with class names each time it is used.</P><H5 CLASS="Head4"><A NAME="pgfId-51886"></A>Runtime Invisible Metadata (Annotations)</H5><P CLASS="Paragraph"><A NAME="pgfId-51884"></A>This language feature lets you avoid writing boilerplate code under many circumstances by enabling tools to generate it from annotations in the source code. The Java Card platform language subset supports the use of annotations which are not visible at runtime. These annotations do not themselves use the runtime visible meta-data annotation <KBD CLASS="Filename-Command">@Retention(RetentionPolicy.RUNTIME)</KBD>.</P><H4 CLASS="Head3"><A NAME="pgfId-51791"></A>2.2.2.2 <A NAME="marker-51790"></A>Keywords</H4><P CLASS="Paragraph"><A NAME="pgfId-35901"></A>The following keywords are supported. Their use is the same as in the Java programming language.</P><BR><TABLE CLASS="Titled" BORDER=1 BORDERCOLORLIGHT="#FFFFFF" BORDERCOLORDARK="#000000" CELLPADDING=5 CELLSPACING=0 DIR="LTR"><CAPTION CLASS="TableCaption"><A NAME="pgfId-49073"> </A> TABLE 2-2 Supported Keywords </CAPTION><TBODY><TR><TD SCOPE="ROW" ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-35904"></A><KBD CLASS="Filename-Command">abstract</KBD><A NAME="marker-47370"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-35906"></A><KBD CLASS="Filename-Command">default</KBD><A NAME="marker-47371"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-35908"></A><KBD CLASS="Filename-Command">if</KBD><A NAME="marker-47386"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-39365"></A><KBD CLASS="Filename-Command">private</KBD><A NAME="marker-47394"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-39385"></A><KBD CLASS="Filename-Command">this</KBD><A NAME="marker-47402"></A></P></TD></TR><TR><TD SCOPE="ROW" ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-35914"></A><KBD CLASS="Filename-Command">boolean</KBD><A NAME="marker-47372"></A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-35916"></A><KBD CLASS="Filename-Command">do</KBD><A NAME="marker-47373"></A></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -