0
0
Javaprogramming~5 mins

Logical operators in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A&&
B||
C!
D&
What does the expression !(true) evaluate to?
Atrue
Bfalse
Cnull
Derror
Which operator returns true if at least one condition is true?
A&&
B!
C||
D^
What is the result of true && false?
Atrue
Berror
Cnull
Dfalse
Which operator always evaluates both sides, even if the first is false?
A&
B||
C&&
D!
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.