Unicode
- Unicode 6.2
Everything is writen in unicode
Unicode Escapes
UnicodeInputCharacter: UnicodeEscape RawInputCharacter UnicodeEscape: \ UnicodeMarker HexDigit HexDigit HexDigit HexDigit UnicodeMarker: u {u} HexDigit: (one of) 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F RawInputCharacter: any Unicode character
Special Chars
- Line Terminators : LF,CR,LFCR
- White Spaces : SP,HT.FF
- Comments : /../ , //
Identifiers
Identifier:
IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
JavaLetter {JavaLetterOrDigit}
JavaLetter:
any Unicode character that is a "Java letter"
JavaLetterOrDigit:
any Unicode character that is a "Java letter-or-digit"
- Two identifiers are the same only if they are identical, that is, have the same Unicode character for each letter or digit. Identifiers that have the same external appearance may yet be different.
- The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.
Keywords, Boolean Literals, Null Literals
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while
- 50, can not be used as identifiers
- treu/false
- null
- after jdk9, underscore cannot be used as identifiers
Integer
IntegerLiteral:
DecimalIntegerLiteral
HexIntegerLiteral
OctalIntegerLiteral
BinaryIntegerLiteral
DecimalIntegerLiteral:
DecimalNumeral [IntegerTypeSuffix]
HexIntegerLiteral:
HexNumeral [IntegerTypeSuffix]
OctalIntegerLiteral:
OctalNumeral [IntegerTypeSuffix]
BinaryIntegerLiteral:
BinaryNumeral [IntegerTypeSuffix]
IntegerTypeSuffix:
(one of)
l L
- Suffix : L for type long
- Decimal : 0 , nonzero [digits], nonzero [underscore] digits
- Hex : 0x(X) HexDigits [undersocre] HexDigits
- Octal : 0 OctalDigits [undersocre] OctalDigits
- Binary : 0b(B) BinaryDigits [undersocre] BinaryDigits
- Undersocre : use to denote digits, as comma in accounting, only between digits, can not be start or end
- Max pos int(32 bits) : 2^31 = 2147483647 / 0x7fff_ffff / 0177_7777_7777 / 0b0111_1111_1111_1111_1111_1111_1111_1111
- Max neg int : -2^31 = -2147483648
Max long(64 bits) : 2^63
Floating
FloatingPointLiteral: DecimalFloatingPointLiteral HexadecimalFloatingPointLiteral DecimalFloatingPointLiteral: Digits . [Digits] [ExponentPart] [FloatTypeSuffix] . Digits [ExponentPart] [FloatTypeSuffix] Digits ExponentPart [FloatTypeSuffix] Digits [ExponentPart] FloatTypeSuffix ExponentPart: ExponentIndicator SignedInteger ExponentIndicator: (one of) e E SignedInteger: [Sign] Digits Sign: (one of) + - FloatTypeSuffix: (one of) f F d D
- Suffix : F for folat, D for double
- Infinities : 1f/0f, -1d/0d, POSITIVE_INFINITY, NEGATIVE_INFINITY
Boolean
ture/ false
Character
- enclosed in single quotes
- UTF-16 code units : \u0000 - \uffff
- Line Terminator not allowed : \u000a,\u000d ; use \n, \r instead
String
- enclosed in double quotes
not accept : \u000a(LF), \u000d(CR) and \u0002(")
package testPackage; class Test { public static void main(String[] args) { String hello = "Hello", lo = "lo"; System.out.print((hello == "Hello") + " "); //true System.out.print((Other.hello == hello) + " "); //true System.out.print((other.Other.hello == hello) + " "); //true System.out.print((hello == ("Hel"+"lo")) + " "); //true, computed at compile System.out.print((hello == ("Hel"+lo)) + " "); //fasle, computed as runtime System.out.println(hello == ("Hel"+lo).intern()); //true, use constant pool } } class Other { static String hello = "Hello"; }
- more compare : Strings
Escapes
EscapeSequence:
\ b (backspace BS, Unicode \u0008)
\ t (horizontal tab HT, Unicode \u0009)
\ n (linefeed LF, Unicode \u000a)
\ f (form feed FF, Unicode \u000c)
\ r (carriage return CR, Unicode \u000d)
\ " (double quote ", Unicode \u0022)
\ ' (single quote ', Unicode \u0027)
\ \ (backslash \, Unicode \u005c)
OctalEscape (octal value, Unicode \u0000 to \u00ff)
OctalEscape:
\ OctalDigit
\ OctalDigit OctalDigit
\ ZeroToThree OctalDigit OctalDigit
OctalDigit:
(one of)
0 1 2 3 4 5 6 7
ZeroToThree:
(one of)
0 1 2 3
Null
- null
Separators (Punctuators)
( ) { } [ ] ; , . ... @ ::
- 12
Operators
= > < ! ~ ? : ->
== >= <= != && || ++ --
+ - * / & | ^ % << >> >>>
+= -= *= /= &= |= ^= %= <<= >>= >>>=
- 38
Ref.
本文由 Ivan Dong 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jul 7, 2023 at 04:32 am