The logical foundation for every 'if' statement, search query, and SQL WHERE clause you'll ever write.
A Boolean is a data type that can only ever be true or false β it's the odd one out among the simple data types (String, char, int, double) because it doesn't store a value/quantity, only a logical state.
Relational operators β compare two values and produce a Boolean result:
| Operator | Meaning |
|---|---|
| > | Greater than |
| >= | Greater than or equal to |
| < | Less than |
| <= | Less than or equal to |
| = / == | Equal to (== in Java for primitive comparison) |
| != / <> | Not equal to |
Logical operators β combine multiple Boolean expressions:
| Operator | Meaning | True when⦠|
|---|---|---|
| NOT | Reverses a Boolean value | The original value was false |
| AND | Both conditions must be true | Condition A is true AND Condition B is true |
| OR | At least one condition must be true | Condition A is true OR Condition B is true (or both) |
Order of operations: NOT is evaluated first, then AND, then OR β but always use brackets to make complex conditions explicit and avoid ambiguity.
Truth tables list every possible combination of input values and the resulting output β for up to 3 variables at this level, you should be able to construct and read one fully.
Example
Truth table for (A AND B) OR C: A=T, B=T, C=F β (T AND T)=T, T OR F = T A=F, B=T, C=F β (F AND T)=F, F OR F = F A=F, B=F, C=T β (F AND F)=F, F OR T = T
These same Boolean logic principles apply directly to search engines (10.2.6), programming language conditions (10.4.8), and SQL WHERE clauses (10.4.11) β master it once, use it everywhere.
π‘ Exam Tip
Common mistake: forgetting that in code, a compound condition needs each side fully written out β e.g. 'age >= 18 AND age <= 65' cannot be shortened to '18 <= age <= 65' the way it can in maths.