Java基础恶补——Operators

[SCJP Sun Certified Programmer for Java 6 Study Guide (Exam 310-065)]  chapter4

 

一. 关系运算符
1. 关系运算符的运算结果总是布尔值(true or false)。

2. 有6个关系运算符: >, >=, <, <=, ==, and !=.  ==  和 != 也被称作 equality operators.

3. 当比较字符时,Java用Unicode值作为其数值。

4. Equality operators:

1) 有2个:== 和 !=.

2) 可应用于4种类型:numbers, characters, booleans, reference variables.

5. 当比较引用变量时,当引用指向的是同一个对象时,== 的结果为true。

 

二. instanceof运算符
1. instanceof 只能应用于引用变量,用于检查1个对象是否是1个特定的类型。

2. The instanceof operator can be used only to test objects (or null) against class types that are in the same class hierarchy.

3. For interfaces, an object passes the instanceof test if any of its superclasses implement the interface on the right side of the instanceof operator.

 

三. 数学运算符
1. 有4个数学运算符: +, -, *, /,

2. % 的运算结果是除数的余数。

3. 表达式的常规运算顺序是从左到右,除非遇到()或优先级较高的运算符。

4. *, /, % 的优先于+, -.

 

四. 字符串连接运算符
1. 如果操作数是1个String,则+表示连接字符串。

2. 如果操作数都是数字类型的,则+表示加运算。

 

五. 自增自减运算符
1. 前缀++和--在应用于表达式运算之前执行;后缀则在表达式运算之后执行。

2. In any expression, both operands are fully evaluated before the operator is applied.

3. final 变量不能++或--。

 

六. Ternary (Conditional Operator)
1. 根据表达式的布尔值返回2个值中的1个:true 返回 ? 左边的值,false则返回右边的值。

 

七. 逻辑运算符
1. The exam covers six "logical" operators: &, |, ^, !, &&, and ||.

2. 逻辑运算符可以应用于2个表达式(!除外,!只能应用于boolean值)。

3. && 和 & 返回 true 当操作数都为 true.

4. || 和 | 返回 true 当操作数中1个或全部为 true.

5. && 和 || 是短路的:&& 当左边的操作数false时,不会执行右边的;|| 当左边的操作数true时,不会执行右边的。

6. & 和 | 是非短路的,两边的操作数都会执行。

7. ^ 返回true当只有1个为true。

8. ! 返回操作数的相反值。

注:BITWISE OPERATORS ARE NOT ON THE EXAM 310-065!

 

 

 

 

你可能感兴趣的:(java基础)