5m left·0%
Reading Time: 5 min
Last Updated: February 26, 2026
Main Ideas: 4
Reading Time: 5 min
Last Updated: February 26, 2026
Main Ideas: 4

Topic 2.5 Notes – Compound Boolean Expressions

Verified for 2027 AP® Computer Science A Exam
Read aloud
Compound Boolean Expressions let you combine multiple true/false conditions into a single decision. Instead of checking one thing at a time, you can express real rules like “must meet requirement A and either B or C.” Everything still evaluates to one final true or false.

1. What Compound Boolean Expressions Are

You already know that comparison operators like <, >=, ==, and != produce Boolean values. For example:

score >= 70

That’s either true or false.

A compound Boolean expression combines two or more Boolean expressions using logical operators:

score >= 70 && attendance >= 90

Each part:

  • score >= 70
  • attendance >= 90

is Boolean. The whole expression is also Boolean.

Now imagine we expand that condition by adding one more possibility:

(score >= 70 && attendance >= 90) || hasSpecialApproval

Visually, you can think of it as a tree of smaller Boolean pieces combined into one final result:

Boolean expression tree for a compound condition

Even when the logic looks complicated, the final result is always one value: true or false.

2. Logical Operators and How They Work

There are exactly three logical operators you need for AP CSA.

NOT !

Flips a Boolean value.

  • !true → false
  • !false → true
  • !passed means “did not pass”

Example:

!isComplete

If isComplete is false, this becomes true.

AND &&

True only if both sides are true.

Truth pattern:

Study guide illustration

Basic Boolean truth tables

Focus on the AND section in the image. It only outputs true in the bottom row, when both inputs are true.

Think: every condition must pass.

Example:

age >= 16 && hasPermit

If either part is false, the whole thing is false.

OR ||

True if at least one side is true.

Study guide illustration

OR (disjunction) truth table

This table shows that the result is false only in the last row, when both inputs are false.

Think: only one condition needs to pass.

Example:

isSenior || hasWaiver

Only false if both are false.

3. Operator Precedence and Grouping

Logical operators follow this order:

  1. !
  2. &&
  3. ||

So Java evaluates:

true || false && false

as:

true || (false && false)

not:

(true || false) && false

That’s because && happens before ||.

When mixing && and ||, parentheses make your intent clear:

(hasTicket && hasID) || isGuest

On quizzes and FRQs, missing parentheses is one of the most common logic mistakes. If the grouping matters to you, make it explicit.

4. Short-Circuit Evaluation

Java sometimes stops early when evaluating && and ||.

With &&

If the first condition is false, Java stops.

false && something

The result must be false, so something is never checked.

With ||

If the first condition is true, Java stops.

true || something

The result must be true.

Why This Matters

1. Preventing Errors

This is safe:

str != null && str.length() > 0

If str is null, Java never checks .length(), so no crash.

Reversing it:

str.length() > 0 && str != null

would cause a NullPointerException.

The order of conditions matters.

2. Side Effects Might Not Run

checkAccess() || logAttempt()

If checkAccess() returns true, logAttempt() never runs.

On the AP exam, they love questions where you assume both sides execute. They don’t.

Key Takeaways

Every compound Boolean expression evaluates to exactly one true or false.
! happens first, then &&, then || unless you use parentheses.
a && b requires both true; a || b requires at least one true.
Short-circuiting means the second part of && or || may never run.
Always check variable != null before calling a method on that variable.
When logic mixes && and ||, use parentheses to match the rule exactly.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse this website.

Notes

1 credit used · 5/5 remaining