3.4-Assigning Values Flashcards
How to master Operators?
-> You should understand 💥️Numeric Promotion💥️ … and when 💥️Casting💥️ is required
What is Casting?
-> It’s a unary operation where one data type is implicitly/explicitly converted as another data type.
When is Casting optional and when it’s mandatory?
🚀️ Casting is unnecessary when converting to a larger or widening data type
🚀️ But it is mandatory when converting to a smaller or narrowing data type.
[Over/Under Flow]
What is the syntax for Casting in Java?
-> By placing the type, enclosed in parentheses, to the left of the value you want to cast. // DOES NOT COMPILE >>> ❌short s = 13 * 5; ❌float f = 2.0 / 1;
// DOES COMPILE ✅short s = (short) (13 * 5); ✅float f = (float)2.0 / 1;
What is the Compound assignment operator PITFALL case?
🤯️⚠️📣️ Compound assignment operator cannot be used when inline declaration.
🧠️ Compound assignment operators automatically perform internally type-casting.
📝️ What does the assignment operator returns?
It returns the value of the assignment