3.5-Relational, Comparisson & Logical Operators Flashcards

1
Q

📝️ What are the Comparisson operators?

A

== | != -> Operators that can be used to check equality

-> Are the same? | Are different values?
🤯️⚠️📣️ There’s a semantic difference between:
-> “Two objects are the same” and…
-> “Two objects are equivalent.”

👀️🧠️ However for numeric and boolean primitives, there is no such distinction.

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

What are the four scenarios for comparisson operators? and what are its PITFALL cases?

A
[SCENARIOS
1°  boolean type operands
2° numeric primitive types operands
3° char primitive types operands
4° Reference types operands
[PITFALLS]
🤯️⚠️📣️ We cannot mix and match types 
   ❌true == 3 | ❌false != "Grape" | ❌10.2 == "Koko" //DOES NOT COMPILE
However...
✅ 5 == 5.0

🤯️⚠️📣️ Two references are equal only if they point to the same object or both point to null.

🤯️⚠️📣️ Comparing null with other null value return true -> (null == null) //RETURNS TRUE

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

What are the Relational operators and its PITFALL case(s)?

A

[PRECEDENCE]
>, >=, < , <= , instanceof

[PITFALLS]
🤯️⚠️📣️ If null is used on the left side of the instanceof operator it returns FALSE

❌The code won’t compile❌
🤖️ If null is used on the right side of the instanceof operator
🤖️ If left-type cannot possibly hold right-type ❌The code won’t compile❌
e.g: Integer instanceOf String

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

What are the logical operators and its precedence?

A

(Bitwise | Logical Operators)

&, |, ^, &&, ||

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

📝️ What are the logical operators behavior?

A

& AND is only true if both operands are true.
| Inclusive OR is only false if both operands are false.
^ Exclusive OR is only true if the operands are different.

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

What are the short-circuit Logical operators?

A

&&, ||

📝️ What does short-circuit means? The second operand is evaluated only if required.

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