Operators |
Associativity |
---|---|
Left to right |
|
! ~ ++ -- + (unary) – (unary) () (cast) new |
Right to left |
* / % |
Left to right |
+ - |
Left to right |
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 |
?: |
Right to left |
= += -= *= /= %= &= |= ^= <<= >>= >>>= |
Right to left |
注意:
- && || ! 的操作數只能用于boolean 或 Boolean
- &? | 的操作數既可以用于boolean(Boolean)或者整形(不僅僅是int型),但兩個操作數的類型必須一致
- ~不能用于boolean(Boolean)型,但可以用于整形,大概是為了和 ! 區別開來吧
- & | 沒有短路計算的
Type |
Storage Requirement |
Range (Inclusive) |
---|---|---|
4 bytes |
–2,147,483,648 to 2,147,483,647 (just over 2 billion) |
|
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 byte |
–128 to 127 |
3、
Type |
Storage Requirement |
Range |
---|---|---|
4 bytes |
approximately ±3.40282347E+38F (6–7 significant decimal digits) |
|
double |
8 bytes |
approximately ±1.79769313486231570E+308 (15 significant decimal digits) |
4、final 實例域(final instance field):可以將實例域定義為final,構建對象時必須初始化這樣得域,也就是說,必須確保在每一個構造器執行之后,這個域的值被設置。但是,靜態常量必須在聲明的同時也被初始化。
5、for each 循環:
for (variable : collection) statment
例如:for (int element : a)
??? ?? ?? System.out.println(element);
該代碼片段打印數組a的每一個元素,一個元素占一行
6、合法的Java標識符:可以以下劃線、字母或美元符號$開頭,后面可以跟下劃線、數字、字母、美元符號。1.42以后的java標識符也可以包含漢字,包括開頭。