1、Java运算符优先级:
Operator Precedence
Operators
|
Associativity
|
[] . () (method call)
|
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)型,但可以用于整形,大概是为了和 ! 区别开来吧
- & | 没有短路计算的
2、
Java Integer Types
Type
|
Storage Requirement
|
Range
(Inclusive)
|
int
|
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
|
char 2 bytes 0 to 65535
3、
Floating-Point Types
Type
|
Storage Requirement
|
Range
|
float
|
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标识符也可以包含汉字,包括开头。