Operators Flashcards

1
Q

What do we need to watch out when using operators?

A

For usage of = in code

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

Which operators have the highest precedence?

A

Post-unary operators (expression++, expression–)

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

What comes after post-unary (expression++, expression–) operators in precedence?

A

Pre-unary operators (++expression, –expression)

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

What is the precedence order of other unary operators (-, !, ~, +, (type)) ?

A

Other unary operators come after pre-unary operators (++expression, –expression)

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

Where does the cast operator ((Type)reference) fit in the precedence order?

A

The cast operator has the same precedence as other unary operators (-, !, ~, +, (type))

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

What operators come after unary operators (-, !, ~, +, (type)) in precedence?

A

Multiplication/division/modulus operators (*, /, %)

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

What is the next level of precedence after multiplication/division/modulus? (*, /, %)

A

Addition/subtraction operators (+, -)

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

Where do shift operators («,&raquo_space;,&raquo_space;>) fall in the precedence order?

A

Shift operators («,&raquo_space;,&raquo_space;>) come after addition/subtraction (+, -)

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

What comes after shift operators («,&raquo_space;,&raquo_space;>) in precedence?

A

Relational operators (<, >, <=, >=, instanceof)

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

What is the precedence of equality operators compared to relational operators? (<, >, <=, >=, instanceof)

A

Equality operators (==, !=) have lower precedence than relational operators

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

In what order do the bitwise operators come?

A

After equality operators (==, !=) - Logical AND (&), then Logical XOR (^), then Logical OR (|)

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

Where do conditional AND (&&) and OR (||) fit in the precedence order?

A

Conditional AND (&&) has higher precedence than conditional OR (||), both come after bitwise operators

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

What is the precedence of the ternary operator?

A

The ternary operator (?:) comes after conditional OR and before assignment operators

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

Where do assignment operators (=, +=, -=, etc.) fall in the precedence order?

A

Assignment operators (=, +=, -=, etc.) have one of the lowest precedences

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

What operator has the lowest precedence?

A

The arrow operator (->) has the lowest precedence

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

What are logical operators?

A

AND (&), inclusive OR (^) and exclusive OR (|)

17
Q

How does logical AND (&) evaluate?

A

true if both values are true

18
Q

How does logical inclusive OR (|) evaluate?

A

false only if both are false

19
Q

How does logical exclusive OR (^) evaluate?

A

true only if both are different

20
Q

How do we call a part of expression that is not evaluated?

A

Unperformed side effect

21
Q

What do we need to watch out when using logical operators?

A

Both values are being evaluated

22
Q

What does unary operator ~ do?

A

Inverts 0s and 1s in literal

23
Q

How do we calculate result of unary operator ~?

A

(n * (-1)) - 1

24
Q

Casting with primitives?

A

Only needed if bigger literal type needs to become smaller literal type

25
Q

What is overflow and underflow?

A

When casting bigger literal to smaller doesn’t fit

26
Q

What do we need to watch out when using instanceOf?

A

Need to watch if we evaluate instanceOf variable that makes sense (eg. Number cannot be instance of String)

27
Q

null instanceOf Object?

A

Always false

28
Q

Numeric promotion?

A

Happens only when statement has numbers, and lower than int are promoted to int, and then calculated

29
Q

null instanceOf null

A

Exception is thrown

30
Q

lower primitive type + bigger primitive type = ?

A

bigger primitive type

31
Q

whole number + float = ?

A

float

32
Q

short + byte = ?

A

int

33
Q

byte hat = 1;
short boots = 2 + hat;

A

Exception, because of the numeric promotion to int. Need to cast it back to short