Chapter III Flashcards

Using operators and decision constructs Working with Java primitive data types and string APIs

1
Q

Order of operator precedence

A

(1) Post-unary operators = ++, - -
(2) Pre-unary operators = ++, - -
(3) Other unary operators = -, !, +, (type)
(4) Multiplication/division/modulus = *, /, %
(5) Addition/subtraction = +,-
(6) Shift operators = <>,&raquo_space;>
(7) Relational operators = , <=, >=, instanceof
(8) Equal to/not equal to = ==, !=
(9) Logical operators = &, |
(10) Short-circuit logical operators = &&, ||
(11) Ternary operators = boolean expression ? expression1 : expression2
(12) Assignment operators = =, +=, -=, *=, /=, %=, &=, |=, «=,&raquo_space;=,&raquo_space;>=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Numeric promotion rules

A

If two values have different data types, Java will automatically promote one of the values to the larger of the two data types.
If one of the values is integral and the other is floting-point, Java will automatically promote the integral value to the floating-point values data type.
Smaller data types, namely, byte, short, and char, are first promoted to int any time they’re used with a Java binary arithmetic operator, even if neither of the operands is int.
After all promotion has occurred and the operands have the same data type, the resulting value will have the same data type as its promoted operands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Equality operators

A
= = (Apply to primitives) returns true if the two values represent the same value.
= = (Apply to objects) returns true if the two values reference the same object.
!= (Apply to primitives) returns true if the two values represent different values.
!= (Apply to objects) returns true if the two values do not reference the same object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Relational Operators

A
< returns true if the value on the left is strictly less than the value on the right.
< = returns true if the value on the left is less than or equal to the value on the right.
> returns true if the value on the left is strictly greater than the value on the right.
> = returns true if the value on the left is greater than or equal to the value on the right.
a instanceof b returns true if the reference that a points to is an instance of a class, subclass, or class that implements a particular interface, as named in b.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Logical operators

A

& logical AND is true only if both values are true.
| inclusive OR is true if at least one of the value is true.
^ exclusive XOR is true only if one value is true and the other is false.
- Short-circuit operators
&& short-circuit AND is true only if both values are true. If the left side is false, then the right side will not be evaluated.
| | short-circuit OR is true if at least one of the values is true. If the left side is true, then the right side will not be evaluated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly