unit 3-4 Flashcards
(50 cards)
What is a boolean expression?
An expression that evaluates to true or false.
What are the boolean literals in Java?
true and false
What operator is used for equality comparison?
==
What does != mean?
Not equal to
What does > mean in Java?
Greater than
What does >= mean?
Greater than or equal to
What does < mean in Java?
Less than
What does <= mean?
Less than or equal to
What operator is used for logical AND?
&&
What operator is used for logical OR?
||
What operator is used for logical NOT?
!
What is the result of true && false?
false
What is the result of true || false?
true
What is the result of !false?
true
What is the correct way to write an if statement in Java?
if (condition) {
// code
}
How do you write an if-else statement?
if (condition) {
// true block
} else {
// false block
}
What is an else if?
An additional condition checked only if previous ones are false.
When is an else block executed?
Only when all previous if/else if conditions are false.
What does this return? “hello”.equals(“Hello”)
false — case-sensitive comparison.
What method is used to compare strings for equality?
.equals()
Can you use == to compare strings reliably?
No. It compares memory addresses, not content.
What is a nested if?
An if inside another if.
What is short-circuit evaluation?
Java stops evaluating a boolean expression as soon as the result is known.
What is DeMorgan’s Law?
Rules for distributing ! across && and ||:
!(A && B) → !A || !B
!(A || B) → !A && !B