Free Online Flashcard Deck

Java Boolean Logic and Selection Free Online FlashCards

Study Java Boolean Logic and Selection with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What values can a Java boolean store?

Back

A boolean stores exactly one of two values: true or false. Java conditions must have type boolean or Boolean; integers such as 1 and 0 cannot serve as conditions automatically.

02
Front

How do = and == differ in Java?

Back

= assigns a value to a variable, while == tests whether two values are equal. For example, score = 90 changes score; score == 90 produces a boolean result.

03
Front

How should Java String contents be compared?

Back

For primitive numeric values, == compares the actual values. For String objects, == compares references; use equals to compare character contents, such as first.equals(second).

04
Front

What do !, &&, and || mean?

Back

! reverses a boolean, && is true only when both operands are true, and || is true when at least one operand is true.

05
Front

What is Java’s logical operator precedence?

Back

Without parentheses, Java evaluates logical operators in this order: ! first, then &&, then ||. Parentheses make compound conditions clearer and can change the grouping.

06
Front

How does short-circuit evaluation work?

Back

With &&, a false first operand prevents evaluation of the second. With ||, a true first operand prevents evaluation of the second. This can avoid errors such as division by zero.

07
Front

What does a one-way if statement do?

Back

An if statement executes its body only when its boolean condition is true. If the condition is false, the body is skipped and execution continues afterward.

08
Front

When should you use if-else?

Back

An if-else statement chooses exactly one of two bodies: the if body when the condition is true, or the else body when it is false.

09
Front

How does an if-else-if chain choose a branch?

Back

An if-else-if chain checks conditions from top to bottom and executes only the first branch whose condition is true. Therefore, condition order matters.

10
Front

What is a nested conditional?

Back

A nested conditional is a conditional inside another conditional. The inner condition is evaluated only if execution reaches it, such as after the outer condition is true.

11
Front

Which if does an else match?

Back

An else attaches to the nearest unmatched if at the same structural level. Braces make the intended association explicit and prevent ambiguity.

12
Front

What are De Morgan’s laws?

Back

De Morgan’s laws are !(a && b) equivalent to !a || !b, and !(a || b) equivalent to !a && !b. Negation switches AND and OR while negating each condition.