Integer Type
Type Storage Requirement Range(Inclusive) int 4 bytes –2,147,483,648 to 2,147,483, 647 short 2 bytes –32,768 to 32,767 long 8 bytes –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 byte 1 bytes –128 to 127
Floating-Point Types
Type Storage Requirement Range(Inclusive) float 4 bytes Approximately ±3.40282347E+38F (6–7 significant decimal digits) double 8 bytes Approximately ±1.79769313486231570E+308(15 significant decimal digits)
Escape Sequences for Special Characters
Escape Sequence Name Unicode Value \b Backspace \u0008 \t Tab \u0009 \n Linefeed \u000a \r Carriage return \u000d \” Double quote \u0022 \’ Single quote \u0027 \ Backslash \u005c
注:编译器优先处理特殊符号,System.out.print(“\u002+\u002”);
Type Conversions
Operator Precedence
Operators Associativity [] . () (method call) Left to right ! ~ ++ – + (unary) - (unary) () (cast) new Right to left ,* / % << >> >>> Left to right < <= > >= instanceof Left to right == != Left to right & Left to right ^ Left to right
?…….| |Left to right| |&&|Left to right| ?…… || |Left to right| |?:|Left to right| ?…..= += -= *= /= %= &= |= ^= <<= >>= >>>= Left to right
Conversions for printf
Conversion Character Type Example d Decimal integer 159 x Hexadecimal integer 9f o Octal integer 237 f Fixed-point floating-point 15.9 e Exponential floating-point 1.59e+01 g General floating-point (the shorter of e and f — a Hexadecimal floating-point 0x1.fccdp3 s String Hello c Character H b boolean true h Hash code 42628b2 tx or Tx Date and time (T forces uppercase) Obsolete, use the java.time classes instead—see Chapter 6 of Volume II % The percent symbol % n The platform-dependent line separator —