📄 3.doc.html
字号:
</i> <code>l L
</code></pre></ul><a name="19247"></a>
An integer literal is of type <code>long</code> if it is suffixed with an ASCII letter <code>L</code> or <code>l</code> (ell); otherwise it is of type <code>int</code> <a href="4.doc.html#9151">(§4.2.1)</a>. The suffix <code>L</code> is preferred, because the letter <code>l</code> (ell) is often hard to distinguish from the digit <code>1</code> (one).<p>
<a name="48345"></a>
A decimal numeral is either the single ASCII character <code>0</code>, representing the integer zero, or consists of an ASCII digit from <code>1</code> to <code>9</code>, optionally followed by one or more ASCII digits from <code>0</code> to <code>9</code>, representing a positive integer:<p>
<ul><pre>
<i>DecimalNumeral:<br>
</i><code>0<br>
</code> <i>NonZeroDigit</i><code> </code><i>Digits</i><sub><i>opt
</i></sub>
<i>Digits:<br>
Digit<br>
Digits</i><code> </code><i>Digit
</i>
<i>Digit:<br>
</i><code> 0<br>
</code><i> NonZeroDigit
</i>
<i>NonZeroDigit: one of<br>
</i><code> 1 2 3 4 5 6 7 8 9
</code></pre></ul><a name="44312"></a>
A hexadecimal numeral consists of the leading ASCII characters <code>0x</code> or <code>0X</code> followed by one or more ASCII hexadecimal digits and can represent a positive, zero, or negative integer. Hexadecimal digits with values 10 through 15 are represented by the ASCII letters <code>a</code> through <code>f</code> or <code>A</code> through <code>F</code>, respectively; each letter used as a hexadecimal digit may be uppercase or lowercase.<p>
<ul><pre>
<i>HexNumeral:<br>
</i><code> 0 x </code><i>HexDigit<br>
</i> <code>0 X </code><i>HexDigit<br>
</i><code> </code>HexNumeral<code> </code>HexDigit
</pre></ul><a name="229443"></a>
The following production from <a href="3.doc.html#100850">§3.3</a> is repeated here for clarity:
<p><ul><pre>
<i>HexDigit:</i> <i>one</i> <i>of<br>
</i><code> 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
</code></pre></ul><a name="48298"></a>
An octal numeral consists of an ASCII digit <code>0</code> followed by one or more of the ASCII digits <code>0</code> through <code>7</code> and can represent a positive, zero, or negative integer.<p>
<ul><pre>
<i>OctalNumeral:<br>
</i><code> 0 </code><i>OctalDigit<br>
OctalNumeral</i><code> </code><i>OctalDigit
</i>
<i>OctalDigit:</i> <i>one</i> <i>of<br>
</i><code> 0 1 2 3 4 5 6 7
</code><a name="231741"></a>
<p>
</pre></ul><a name="231738"></a>
Note that octal numerals are always consist of two or more digits; <code>0</code> is always considered to be a decimal numeral-not that it matters much in practice, for the numerals <code>0</code>, <code>00</code>, and <code>0x0</code> all represent exactly the same integer value.<p>
<a name="231836"></a>
The largest decimal literal of type <code>int</code> is <code>2147483648</code> (<img src="3.doc.anc.gif">). All decimal literals from <code>0</code> to <code>2147483647</code> may appear anywhere an <code>int</code> literal may appear, but the literal <code>2147483648</code> may appear only as the operand of the unary negation operator <code>-</code>.<p>
<a name="229493"></a>
The largest positive hexadecimal and octal literals of type <code>int</code> are <code>0x7fffffff</code> and <code>017777777777</code>, respectively, which equal <code>2147483647</code> (<img src="3.doc.anc1.gif">). The most negative hexadecimal and octal literals of type <code>int</code> are <code>0x80000000</code> and <code>020000000000</code>, respectively, each of which represents the decimal value <code>-2147483648</code> (<img src="3.doc.anc2.gif">). The hexadecimal and octal literals <code>0xffffffff</code> and <code>037777777777</code>, respectively, represent the decimal value <code>-1</code>.<p>
<a name="229508"></a>
See also <code>Integer.MIN_VALUE</code> <a href="javalang.doc6.html#2390">(§20.7.1)</a> and <code>Integer.MAX_VALUE</code> <a href="javalang.doc6.html#2391">(§20.7.2)</a>.<p>
<a name="48314"></a>
A compile-time error occurs if a decimal literal of type <code>int</code> is larger than <code>2147483648</code> (<img src="3.doc.anc3.gif">), or if the literal <code>2147483648</code> appears anywhere other than as the operand of the unary <code>-</code> operator, or if a hexadecimal or octal <code>int</code> literal does not fit in 32 bits.<p>
<a name="48319"></a>
Examples of <code>int</code> literals:<p>
<pre><a name="48320"></a> 0 2 0372 0xDadaCafe 1996 0x00FF00FF
</pre><a name="21371"></a>
The largest decimal literal of type <code>long</code> is <code>9223372036854775808L</code> (<img src="3.doc.anc4.gif">). All decimal literals from <code>0L</code> to <code>9223372036854775807L</code> may appear anywhere a <code>long</code> literal may appear, but the literal <code>9223372036854775808L</code> may appear only as the operand of the unary negation operator <code>-</code>.<p>
<a name="21372"></a>
The largest positive hexadecimal and octal literals of type <code>long</code> are <code>0x7fffffffffffffffL</code> and <code>0777777777777777777777L</code>, respectively, which equal <code>9223372036854775807L</code> (<img src="3.doc.anc5.gif">). The literals <code>0x8000000000000000L</code> and <code>01000000000000000000000L</code> are the most negative <code>long</code> hexadecimal and octal literals, respectively. Each has the decimal value<code> -9223372036854775808L</code> (<img src="3.doc.anc6.gif">). The hexadecimal and octal literals <code>0xffffffffffffffffL</code> and <code>01777777777777777777777L</code>, respectively, represent the decimal value <code>-1L</code>.<p>
<a name="229516"></a>
See also <code>Long.MIN_VALUE</code> <a href="javalang.doc7.html#2397">(§20.8.1)</a> and <code>Long.MAX_VALUE</code> <a href="javalang.doc7.html#14434">(§20.8.2)</a>.<p>
<a name="76695"></a>
A compile-time error occurs if a decimal literal of type <code>long</code> is larger than <code>9223372036854775808L</code> (<img src="3.doc.anc7.gif">), or if the literal <code>9223372036854775808L</code> appears anywhere other than as the operand of the unary <code>-</code> operator, or if a hexadecimal or octal <code>long</code> literal does not fit in 64 bits.<p>
<a name="46763"></a>
Examples of <code>long</code> literals:<p>
<pre><a name="46765"></a> 0l 0777L 0x100000000L 2147483648L  0xC0B0L
</pre><a name="230798"></a>
<h3>3.10.2 Floating-Point Literals</h3>
<a name="232095"></a>
See <a href="4.doc.html#9208">§4.2.3</a> for a general discussion of the floating-point types and values.
<p><a name="232096"></a>
A <i>floating-point literal</i> has the following parts: a whole-number part, a decimal point (represented by an ASCII period character), a fractional part, an exponent, and a type suffix. The exponent, if present, is indicated by the ASCII letter <code>e</code> or <code>E</code> followed by an optionally signed integer.<p>
<a name="48344"></a>
At least one digit, in either the whole number or the fraction part, and either a decimal point, an exponent, or a float type suffix are required. All other parts are optional.<p>
<a name="76707"></a>
A floating-point literal is of type <code>float</code> if it is suffixed with an ASCII letter <code>F</code> or <code>f</code>; otherwise its type is <code>double</code> and it can optionally be suffixed with an ASCII letter <code>D</code> or <code>d</code>.<p>
<ul><pre>
<i>FloatingPointLiteral:<br>
Digits</i><code> . </code><i>Digits</i><sub><i>opt</i></sub><code> </code><i>ExponentPart</i><sub><i>opt</i></sub><code> </code><i>FloatTypeSuffix</i><sub><i>opt<br>
</i></sub> <code>. </code><i>Digits</i><code> </code><i>ExponentPart</i><sub><i>opt</i></sub><code> </code><i>FloatTypeSuffix</i><sub><i>opt<br>
</i></sub> <i>Digits</i><code> </code><i>ExponentPart</i><code> </code><i>FloatTypeSuffix</i><sub><i>opt<br>
</i></sub><i>Digits</i><code> </code><i>ExponentPart</i><sub><i>opt</i></sub><code> </code><i>FloatTypeSuffix
</i>
<i>ExponentPart:<br>
</i> <i>ExponentIndicator</i><code> </code><i>SignedInteger
</i>
<i>ExponentIndicator:</i> <i>one</i> <i>of<br>
</i> <code>e E
</code>
<i>SignedInteger:<br>
</i> <i>Sign</i><sub><i>opt</i></sub><code> </code><i>Digits
</i>
<i>Sign:</i> <i>one</i> <i>of<br>
</i> <code>+ -
</code>
<i>FloatTypeSuffix:</i> <i>one</i> <i>of<br>
</i> <code>f F d D
</code></pre></ul><a name="230642"></a>
The Java types <code>float</code> and <code>double</code> are IEEE 754 32-bit single-precision and 64-bit double-precision binary floating-point values, respectively.<p>
<a name="230643"></a>
The details of proper input conversion from a Unicode string representation of a floating-point number to the internal IEEE 754 binary floating-point representation are described for the methods <code>valueOf</code> of class <code>Float</code> <a href="javalang.doc8.html#7256">(§20.9.17)</a> and class <code>Double</code> <a href="javalang.doc9.html#1541">(§20.10.16)</a> of the package <code>java.lang</code>.<p>
<a name="76740"></a>
The largest positive finite <code>float</code> literal is <code>3.40282347e+38f</code>. The smallest positive finite nonzero literal of type <code>float</code> is <code>1.40239846e-45f</code>. The largest positive finite <code>double</code> literal is <code>1.79769313486231570e+308</code>. The smallest positive finite nonzero literal of type <code>double</code> is <code>4.94065645841246544e-324</code>.<p>
<a name="229595"></a>
See <code>Float.MIN_VALUE</code> <a href="javalang.doc8.html#14404">(§20.9.1)</a> and <code>Float.MAX_VALUE </code><a href="javalang.doc8.html#2303">(§20.9.2)</a>; see also <code>Double.MIN_VALUE</code> <a href="javalang.doc9.html#3571">(§20.10.1)</a> and <code>Double.MAX_VALUE </code><a href="javalang.doc9.html#3573">(§20.10.2)</a>.<p>
<a name="50569"></a>
A compile-time error occurs if a nonzero floating-point literal is too large, so that on rounded conversion to its internal representation it becomes an IEEE 754 infinity. A Java program can represent infinities without producing a compile-time error by using constant expressions such as <code>1f/0f</code> or <code>-1d/0d</code> or by using the predefined constants <code>POSITIVE_INFINITY</code> and <code>NEGATIVE_INFINITY</code> of the classes <code>Float</code> <a href="javalang.doc8.html#14394">(§20.9)</a> and <code>Double</code> <a href="javalang.doc9.html#14390">(§20.10)</a>.<p>
<a name="229608"></a>
A compile-time error occurs if a nonzero floating-point literal is too small, so that, on rounded conversion to its internal representation, it becomes a zero. A compile-time error does not occur if a nonzero floating-point literal has a small value that, on rounded conversion to its internal representation, becomes a nonzero denormalized number.<p>
<a name="26899"></a>
Predefined constants representing Not-a-Number values are defined in the classes <code>Float</code> and <code>Double</code> as <code>Float.NaN</code> <a href="javalang.doc8.html#1411">(§20.9.5)</a> and <code>Double.NaN</code> <a href="javalang.doc9.html#13844">(§20.10.5)</a>.<p>
<a name="26906"></a>
Examples of <code>float</code> literals:<p>
<pre><a name="51298"></a> 1e1f 2.f .3f 0f 3.14f 6.022137e+23f
</pre><a name="48365"></a>
Examples of <code>double</code> literals:<p>
<pre><a name="48366"></a> 1e1 2. .3 0.0 3.14 1e-9d 1e137
</pre><a name="23781"></a>
There is no provision for expressing floating-point literals in other than decimal radix. However, method <code>intBitsToFloat</code> <a href="javalang.doc8.html#5683">(§20.9.23)</a> of class <code>Float</code> and method <code>longBitsToDouble</code> <a href="javalang.doc9.html#13864">(§20.10.22)</a> of class <code>Double</code> provide a way to express floating-point values in terms of hexadecimal or octal integer literals. For example, the value of:<p>
<pre><a name="23788"></a>Double.longBitsToDouble(0x400921FB54442D18L)
</pre><a name="231039"></a>
is equal to the value of <code>Math.PI</code> <a href="javalang.doc10.html#36322">(§20.11.2)</a>.
<p><a name="49652"></a>
<h3>3.10.3 Boolean Literals</h3>
<a name="49657"></a>
The <code>boolean</code> type has two values, represented by the literals <code>true</code> and <code>false</code>,
formed from ASCII letters.
<p><a name="229664"></a>
A <i>boolean literal</i> is always of type <code>boolean</code>.<p>
<ul><pre>
<i>BooleanLiteral:</i> <i>one</i> <i>of<br>
</i><code> true false
</code></pre></ul><a name="100960"></a>
<h3>3.10.4 Character Literals</h3>
<a name="100964"></a>
A <i>character literal</i> is expressed as a character or an escape sequence, enclosed in
ASCII single quotes. (The single-quote, or apostrophe, character is <code>\u0027</code>.)
<p><a name="229640"></a>
A character literal is always of type <code>char</code>.<p>
<ul><pre>
<i>CharacterLiteral:<br>
</i> <code>' </code><i>SingleCharacter</i><code> '<br>
' </code><i>EscapeSequence</i><code> '
</code>
<i>SingleCharacter:<br>
</i> <i>InputCharacter</i> but not <code>'</code> or <code>\
</code></pre></ul><a name="100967"></a>
The escape sequences are described in <a href="3.doc.html#101089">§3.10.6</a>.
<p><a name="229112"></a>
As specified in <a href="3.doc.html#231571">§3.4</a>, the characters CR and LF are never an <i>InputCharacter</i>; they are recognized as constituting a <i>LineTerminator</i>.<p>
<a name="100968"></a>
It is a compile-time error for the character following the <i>SingleCharacter</i> or <i>EscapeSequence</i> to be other than a <code>'</code>.<p>
<a name="229137"></a>
It is a compile-time error for a line terminator to appear after the opening <code>'</code> and before the closing <code>'</code>.<p>
<a name="229739"></a>
The following are examples of <code>char</code> literals:<p>
<pre><a name="231014"></a>
'a'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -