random important facts Flashcards

1
Q

java precedence rules (high to low)

A
parentheses:( )
unary ops: +x -x ++x –-x x++ x-- !x
multiply/divide: * / %
add/subtract: + -
comparisons: < > <= >=
equality: == !=
logical and: &amp;&amp; 
logical or: ||
assignments:= += *= /= %= (these are right to left associative)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

short-circuiting

A

As soon as Java knows an answer, it quits evaluating the expression (regardless of what the 2nd expression is)

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

is (++x==0) executed?

int x = 0, y = 1;
if ((y > 1) && (++x == 0)){
}

A

no, because (y>1) is false, java stops evaluating the expression, before it reaches the 2nd part.

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

break

A

allows you to exist immediately from a loop
(while, do-while, for)

(only use break when loop condition is always true)

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

continue

A

jumps to the bottom of the loop immediately ( } ), and starts the next iteration

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

math.

A

math. provides static services

methods: math.add, math.ceil, math.floor, math.pow, math.random (values btwn 0-1

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

switch statement

A

replacement for cascading if-else statements (if tested expression is an integer, string, or enum)

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

switch statement code

A
switch
(〈control-expression〉) { 
case〈case-label-1〉:
〈statement-sequence-1〉
break; 
case〈case-label-2〉:
〈statement-sequence-2〉
break; 
…
case〈case-label-n〉:
〈statement-sequence-n〉
break; 
default:〈default-statement-sequence〉
break; 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

control expression

A

can be of one of the following types:

char, int, short, byte, String, enum

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

“break” statement

A

jumps out of the switch statement. Otherwise control
flow just “falls through” into the next case
(falling though
behavior is handy, because it allows you to combine cases)

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

floating point

A

you can never use == to compare floating points. Check if 2 numbers are within a certain tolerance of each other:
Math.abs((3.9-3.8) - 0.1)

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