Language Basics: Operators Flashcards
What does the ternary operator ?: operator do?
This operator is also known as the ternary operator because it uses three operands. If first operand is true, then do second operand. Otherwise, do third operand.
What does the instanceof operator do?
The instanceof operator compares an object to a specified type. You can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface.
What is the difference between prefix (++i) and postfix(i++)?
++i will give the result of the new i.
i++ will give the result of the original i and store the new i for the next action.
What does the unary bitwise complement operator ~ do?
Inverts a bit pattern; it can be applied to any of the integral types, making every “0” a “1” and every “1” a “0”. For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is “00000000” would change its pattern to “11111111”.
result -= 1;
Result = result - 1;
result *= 2;
result = result*2;