⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 concepts.doc.html

📁 Java编程规范
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html><head><title>VM Spec  Java Programming  Language Concepts</title></head><body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000><table width=100%><tr><td><a href="VMSpecTOC.doc.html">Contents</a> | <a href="Introduction.doc.html">Prev</a> | <a href="Overview.doc.html">Next</a> | <a href="VMSpecIX.fm.html">Index</a></td><td align=right><i><i>The Java<sup><font size=-2>TM</font></sup> <sup><font size=-2>TM</font></sup>Virtual Machine Specification</i></i></td></tr></table><hr><br> <a name="27073"></a><p><strong>CHAPTER 2 </strong></p><a name="27074"></a><h1>Java Programming Language Concepts</h1><hr><p><a name="27075"></a>The Java virtual machine was designed to support the Java programming language.Some concepts and vocabulary from the Java programming language are thus useful when attempting to understand the virtual machine. This chapter gives an overview intended to support the specification of the Java virtual machine, but is not itself a part of that specification. <p><a name="33110"></a>The content of this chapter has been condensed from the first edition of <i>The Java</i><sup><font size=-2>TM</font></sup><i> Language Specification</i>, by James Gosling, Bill Joy, and Guy Steele.<a href="#33132"><sup>1</sup></a> Readers familiar with the Java programming language, but not with <i>The</i> <i>Java</i><sup><font size=-2>TM</font></sup><i> Language Specification</i>, should at least skim this chapter for the terminology it introduces. Any discrepancies between this chapter and <i>The Java</i><sup><font size=-2>TM</font></sup><i> Language Specification </i>should be resolved in favor of <i>The Java</i><sup><font size=-2>TM</font></sup><i> Language Specification</i>. <p><a name="22928"></a>This chapter does not attempt to provide an introduction to the Java programming language. For such an introduction, see <i>The Java</i><sup><font size=-2>TM</font></sup><i> Programming Language, Second Edition</i>, by Ken Arnold and James Gosling.<p><a name="25310"></a><hr><h2>2.1    Unicode</h2><a name="39673"></a>Programs written in the Java programming language supported by JDK release 1.1.7 and the Java 2 platform, v1.2 use the<i> Unicode</i> character encoding, version 2.1, as specified in <em>The Unicode Standard, Version 2.0</em>, ISBN 0-201-48345-9, and the update information for Version 2.1 of the Unicode Standard available at <code>http://www.unicode.org</code>. Programs written in the Java programming language used version2.0.14 of the Unicode Standard in JDK releases 1.1 through 1.1.6 and used version1.1.5 of the Unicode Standard in JDK release 1.0.<p><a name="23148"></a>Except for comments, identifiers <a href="Concepts.doc.html#25339">(&#167;2.2)</a>, and the contents of character and string literals <a href="Concepts.doc.html#20359">(&#167;2.3)</a>, all input elements in a program written in the Java programming language are formed from only <i>ASCII</i> characters. ASCII (ANSI X3.4) is the American Standard Code for Information Interchange. The first 128 characters of the Unicode character encoding are the ASCII characters.<p><a name="25339"></a><hr><h2>2.2    Identifiers</h2><a name="28702"></a>An <i>identifier</i> is an unlimited-length sequence of Unicode <i>letters</i> and <i>digits</i>, the first of which must be a letter. Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today. This allows programmers to use identifiers in their programs that are written in their native languages.<p><a name="23858"></a>The method <a href="Concepts.doc.html#16317">(&#167;2.10)</a> <code>Character.isJavaLetter</code> returns <code>true</code> when passed a Unicode character that is considered to be a letter in an identifier. The method <code>Character.isJavaLetterOrDigit</code> returns <code>true</code> when passed a Unicode character that is considered to be a letter or digit in an identifier.<p><a name="29956"></a>Two identifiers are the same only if they have the same Unicode character for each letter or digit; identifiers that have the same external appearance may still be different. An identifier must not be the same as a boolean literal <a href="Concepts.doc.html#20359">(&#167;2.3)</a>, the null literal <a href="Concepts.doc.html#20359">(&#167;2.3)</a>, or a keyword in the Java programming language.<p><a name="20359"></a><hr><h2>2.3    Literals</h2>A <i>literal</i> is the source code representation of a value of a primitive type <a href="Concepts.doc.html#19511">(&#167;2.4.1)</a>, the <code>String</code> type <a href="Concepts.doc.html#25486">(&#167;2.4.8)</a>, or the null type <a href="Concepts.doc.html#22930">(&#167;2.4)</a>. String literals and, more generally, strings that are the values of constant expressions are "interned" so as to share unique instances, using the method <code>String.intern</code>. <p><a name="27355"></a>The null type has one value, the null reference, denoted by the literal <code>null</code>. The <code>boolean</code> type has two values, denoted by the literals <code>true</code> and <code>false</code>.<p><a name="22930"></a><hr><h2>2.4    Types and Values</h2><a name="17177"></a>The Java programming language is <i>strongly typed</i>, which means that every variable and every expression has a type that is known at compile time. Types limit the valuesthat a variable <a href="Concepts.doc.html#17203">(&#167;2.5)</a> can hold or that an expression can produce, limit the operationssupported on those values, and determine the meaning of those operations. Strong typing helps detect errors at compile time. <p><a name="23869"></a>The types of the Java programming language are divided into two categories: <i>primitive types</i> <a href="Concepts.doc.html#19511">(&#167;2.4.1)</a> and <i>reference types</i> <a href="Concepts.doc.html#29375">(&#167;2.4.6)</a>. There is also a special <i>null type</i>, the type of the expression <code>null</code>, which has no name. The null reference is the only possible value of an expression of null type and can always be converted to any reference type. In practice, the programmer can ignore the null type and just pretend that <code>null</code> is a special literal that can be of any reference type.<p><a name="23205"></a>Corresponding to the primitive types and reference types, there are two categories of data values that can be stored in variables, passed as arguments, returned by methods, and operated upon: <i>primitive values</i> <a href="Concepts.doc.html#19511">(&#167;2.4.1)</a> and <i>reference values</i> <a href="Concepts.doc.html#29375">(&#167;2.4.6)</a>.<p><a name="19511"></a><h3>2.4.1    Primitive Types and Values</h3><a name="27843"></a>A <i>primitive type</i> is a type that is predefined by the Java programming language and named by a reserved keyword. <i>Primitive values</i> do not share state with other primitivevalues. A variable whose type is a primitive type always holds a primitive value of that type.<a href="#27846"><sup>2</sup></a><p><a name="23025"></a>The primitive types are the <code>boolean</code> type and the <i>numeric types</i>. The numeric types are the <i>integral types</i> and the <i>floating-point types. </i><p><a name="23026"></a>The integral types are <code>byte</code>, <code>short</code>, <code>int</code>, and <code>long</code>, whose values are 8-bit, 16-bit, 32-bit, and 64-bit signed two's-complement integers, respectively, and <code>char</code>, whose values are 16-bit unsigned integers representing Unicode characters <a href="Concepts.doc.html#25310">(&#167;2.1)</a>. <p><a name="19367"></a>The floating-point types are <code>float</code> and <code>double</code>, which are conceptually associated with the 32-bit single-precision and 64-bit double-precision IEEE 754 values and operations as specified in <i>IEEE Standard for Binary Floating-Point Arithmetic</i>, ANSI/IEEE Standard 754-1985 (IEEE, New York). <p><a name="23033"></a>The <code>boolean</code> type has the truth values <code>true</code> and <code>false</code>.<p><a name="17876"></a><h3>2.4.2    Operators on Integral Values</h3><a name="17881"></a>The Java programming language provides a number of operators that act on integral values, including numerical comparison, arithmetic operators, increment and decrement,bitwise logical and shift operators, and numeric cast <a href="Concepts.doc.html#18168">(&#167;2.6.9)</a>.<p><a name="20881"></a>Operands of certain unary and binary operators are subject to numeric promotion <a href="Concepts.doc.html#16021">(&#167;2.6.10)</a>.<p><a name="17886"></a>The built-in integer operators do not indicate (positive or negative) overflow in any way; they wrap around on overflow. The only integer operators that can throw an exception are the integer divide and integer remainder operators, which can throw an <code>ArithmeticException</code> if the right-hand operand is zero.<p><a name="33376"></a>Any value of any integral type may be cast to or from any numeric type. There are no casts between integral types and the type <code>boolean</code>.<p><a name="33377"></a><h3>2.4.3    Floating-Point Types, Value Sets, and Values</h3><a name="34259"></a>The IEEE 754 standard includes not only positive and negative sign-magnitude numbers, but also positive and negative zeros, positive and negative <i>infinities</i>, and a special <i>Not-a-Number </i>value (hereafter abbreviated as "NaN"). The NaN value is used to represent the result of certain invalid operations such as dividing zero by zero.<p><a name="34556"></a>Every implementation of the Java programming language is required to support two standard sets of floating-point values, called the <i>float value set</i> and the <i>double value set</i>. In addition, an implementation of the Java programming language may support either or both of two extended-exponent floating-point value sets, called the<i> float-extended-exponent value set</i> and the<i> double-extended-exponent value set</i>. These extended-exponent value sets may, under certain circumstances, be used instead of the standard value sets to represent the values of expressions of type float or double.<p><a name="34707"></a>The finite nonzero values of any floating-point value set can all be expressed in the form s &#183; <i>m</i>&#183; &#32;2<sup>(e &#32;-N &#32;+ &#32;1)</sup>, where <i>s</i> is +1 or -1, <i>m</i> is a positive integer less than 2<sup>N</sup>, and <i>e</i> is an integer between <i>E</i>min = - (2<sup>K &#32;- &#32;1</sup>-2) and <i>E</i>max = 2<sup>K &#32;- &#32;1</sup>-1, inclusive, and where <i>N</i> and <i>K</i> are parameters that depend on the value set. Some values can be represented in this form in more than one way; for example, supposing that a value <i>v</i> in a value set might be represented in this form using certain values for <i>s</i>, <i>m</i>, and <i>e</i>, then if it happened that <i>m</i> was even and <i>e</i> was less than 2<sup>K &#32;-1</sup>, one could halve <i>m</i> and increase <i>e</i> by 1 to produce a second representation for the same value <i>v</i>. A representation in this form is called <i>normalized</i> if <i>m</i> <img src="chars/gtequal.gif"> 2<sup>N &#32;-1</sup>; otherwise the representation is said to be <i>denormalized</i>. If a value in a value set cannot be represented in such a way that <i>m</i> <img src="chars/gtequal.gif"> 2<sup>N &#32;-1</sup>, then the value is said to be a <i>denormalized value</i>, because it has no normalized representation.<p><a name="34798"></a>The constraints on the parameters <i>N</i> and <i>K</i> (and on the derived parameters <i>E</i>min and <i>E</i>max) for the two required and two optional floating-point value sets are summarized in <a href="Concepts.doc.html#34798">Table 2.1</a>.<p><Table Border="1"><tr><th><b><i></i></b><b><i>Parameter</i></b><th><b><i></i></b><b><i>float</i></b><th><b><i>float-extended-exponent</i></b><th><b><i></i></b>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -