Operators_SUMMARY Flashcards
What is the Operators Precedence Table?
<>
- Unary
- Arithmetic
- Shift Bitwise
- Relational
- Comparisson
- Logical
- Ternary
- Assignment
📝️What are the Unary Operators, It’s precedence and PITFALL case(s)?
Post-increment/Post-decrement--++ \++--Pre-increment/decrement \+ Unary plus - Unary minus ~ Bitwise complement ! Logical Complement Operator (type) Casting operator
🧠️🤯️⚠️📣️ If a post-prefix operator is used in both sides of a assignment expression, the variable won’t be incremented.
🧠️🤯️⚠️📣️ Bitwise complement = - (N+1)
📝️ What is a Binary operator, it’s SYNTAX and PITFALL case(s)?
A binary operator is an operator that operates on two operands and manipulates them to return a result.
⚠️📣️ SYNTAX => oprnd1 BINARYOPERATOR oprnd2
⚠️📣️ Numeric Promotion
⚠️📣️ FloorVAlue
📝️ What are the Arithmetic operators, it’s precedence and PITFALL case(s)?
*, /, %, +, -
🧠️🤯️⚠️📣️ Arithmetic Operators lead to NUMERIC PROMOTION Type
o When applying an arithmetic operator ( +|-||/|% ) the result type promotes to int **
o If either operand is double|float|long type, the result is converted to double|float|long
🧠️🤯️⚠️📣️ What does Numeric promotion means?
o When applying an arithmetic operator ( +|-||/|% ) the result type promotes to int **
o If either operand is double|float|long type, the result is converted to double|float|long
⚠️📣️ Compound Assignment converts type automatically to required assignment type
📝️ What is the arithmetic operator that may be applied to String values?
Only the addition operators + and +=, which results in String concatenation.
📝️ What are the Relational Operators and it’s PITFALL case(s)?
Operators which compare two expressions and return a boolean value.
>, >=,
🧠️🤯️⚠️📣️ instanceof PITFALLS:
✅ If null is used on the left side of the instanceof operator it returns FALSE
❌ If null is used on the right side of the instanceof operator ❌The code won’t compile❌
❌ If right-side type cannot possibly hold left-type ❌The code won’t compile❌
What are the Comparisson Operators and it’s PITFALL case(s)?
==, !=
🧠️🤯️⚠️📣️ Comparison Operators PITFALLS
⚠️ There is a semantical difference between:
-> Objects are equivalent
-> Objects are the same
🤯️ There is no such distinction for primitive types
🤯️ When comparing operands should be from the same type
What are the Logical Operators (Bitwise + shortCircuit) and it’s PITFALL case(s)?
& Only TRUE if both operands are true
| Only FALSE if both operands are false
^ Only TRUE if both operands are different
SHORT-CIRCUIT: &&, ||
-> Second operand gets evaluated only if necessary
🧠️🤯️⚠️📣️ Logical Operators PITFALLS?
❌ Whatch out when the Logical Complement is being used.
❌ Don’t confuse Bitwise OR with short-circuit OR
⚠️ XOR (Exclusive OR) true ✅^❌ or ❌^✅
What is the Ternary Operator and its PITFALL case(s)?
? :
🧠️🤯️⚠️📣️ Ternary Operator PITFALLS?
⚠️ When having composed ternary operators whathout it’s balanced. -> Meaning each ‘?’ operator has its counterpart ‘:’
🧠️🤯️⚠️📣️ When assigning the result of a ternary operation expression results type should match
What are the Assignment Operators, its Precedence and PITFALL case(s)?
=, +=, -=, *=, /=
🧠️🤯️⚠️📣️ Compound assignment can’t be used at inline declarations