Boolean Literals: true and false
What you'll learn: How to write the only two possible boolean values in Java using the keywords true and false.
The Two Boolean Values
In Java, boolean variables can hold exactly two values, and those values are written using special keywords: true and false. These are called boolean literals — the actual values you assign to boolean variables.
Here's the important part: unlike some other programming languages, Java uses the words true and false, not numbers like 1 and 0. If you try to assign 1 or 0 to a boolean variable, Java will give you a compilation error.
Writing Boolean Literals
boolean isJavaFun = true;
boolean isRaining = false;
Notice that true and false are lowercase — Java is case-sensitive, so True or FALSE won't work.
Why Not 0 and 1?
Think of it like a light switch with labels. In Java, the switch positions are clearly marked "true" and "false," not "1" and "0." This makes your code more readable and prevents accidental confusion between boolean logic and arithmetic. Some languages use 1 for true and 0 for false, but Java enforces a strict separation between numbers and boolean values.
// This works:
boolean ready = true;
// This does NOT work:
boolean ready = 1; // Compilation error!
Key Takeaway: Boolean literals in Java are the keywords true and false (lowercase), never the numbers 1 or 0. This keeps boolean logic clear and prevents mixing boolean values with numeric calculations.