Booleans in conditions
A comparison like age >= 18 is an expression with a value, and that value is a boolean: true or false. It can be stored in a variable, printed, or used later as a condition:
int age = 20;
boolean adult = age >= 18;
System.out.println("Adult: " + adult);
if (adult) {
System.out.println("Welcome in.");
}
Adult: true
Welcome in.if (adult) reads naturally: the condition is the variable itself, so there's no need to write if (adult == true).
A well-named boolean variable makes a condition easier to read, especially when the test is long or used more than once. Names like adult, isRaining or hasTicket work well: they read like yes-or-no questions.