Skip to content
Justice Tech School

Booleans and Conditions

A boolean is true or false. Comparisons produce booleans. Combine them with && (and), || (or) and ! (not). Java does not treat numbers as booleans like some languages do.

Example
boolean isAdult = 20 >= 18;
boolean hasTicket = false;
System.out.println(isAdult && hasTicket);
System.out.println(isAdult || hasTicket);
System.out.println(!hasTicket);

Result

false
true
true

Exercise

Reverse a boolean.

boolean no = yes;

Quiz Test

Can an int be used as a condition in Java?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.