Recall & Review
beginner
What are the three main logical operators in Java?
The three main logical operators in Java are:<br>1. AND (&&)<br>2. OR (||)<br>3. NOT (!)
Click to reveal answer
beginner
What does the AND (&&) operator do in Java?
The AND (&&) operator returns true only if both conditions on its sides are true. If either condition is false, it returns false.
Click to reveal answer
beginner
Explain the OR (||) operator in Java.
The OR (||) operator returns true if at least one of the conditions is true. It returns false only if both conditions are false.
Click to reveal answer
beginner
What does the NOT (!) operator do in Java?
The NOT (!) operator reverses the value of a boolean expression. If the expression is true, NOT makes it false, and vice versa.
Click to reveal answer
intermediate
What is the difference between & and && in Java?
&& is a short-circuit AND operator: it stops checking if the first condition is false.<br>& is a bitwise AND operator but can also be used as a logical AND without short-circuiting (checks both conditions always).
Click to reveal answer
Which logical operator returns true only if both conditions are true?
✗ Incorrect
&& is the logical AND operator that returns true only if both sides are true.
What does the expression !(true) evaluate to?
✗ Incorrect
The NOT operator (!) reverses true to false.
Which operator returns true if at least one condition is true?
✗ Incorrect
|| is the logical OR operator that returns true if either condition is true.
What is the result of true && false?
✗ Incorrect
AND (&&) returns false if any condition is false.
Which operator always evaluates both sides, even if the first is false?
✗ Incorrect
& is the non-short-circuit AND operator that evaluates both sides.
Explain how the logical AND (&&) and OR (||) operators work in Java with examples.
Think about when you want both conditions to be true versus when only one needs to be true.
You got /3 concepts.
Describe the difference between the short-circuit AND (&&) and the bitwise AND (&) operators in Java.
Consider efficiency and when both conditions must be evaluated.
You got /3 concepts.