Java Booleans & Relational Operators
Booleans in Java are primitive values that can only be either `true` or `false`. Relational comparison operators compare two numbers or primitives and evaluate to a boolean result, forming the bedrock of program decision-making.
"Think of comparison operators as security checkpoint questions. "Is passenger age >= 18?" The answer is strictly a boolean: YES (true) or NO (false)."
Deep Dive: How It Works
Relational operators: `==` (equal to), `!=` (not equal to), `>` (greater than), `<` (less than), `>=` (greater or equal), `<=` (less or equal).
In Java, booleans are distinct from numbers: `1` is NOT equivalent to `true`, and `0` is NOT equivalent to `false` (unlike C/C++ or Python).
Syntax Blueprint
boolean isAdult = age >= 18; boolean isEqual = x == y; boolean isDifferent = a != b;
Comparisons evaluate directly into a boolean value true or false.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using single = inside comparison: if (x = 5)Why it happens: Single = assigns value 5 to x instead of testing equality.
How to fix: Always use double == for checking equality: if (x == 5).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Check passing exam score
Given studentScore = 78 and passingScore = 70, check if the student passed.
Declare a boolean "hasPassed" and print "Passed: " + hasPassed.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.