Utilizor
Contact Us

Java Booleans

True or False values.

Examples

Boolean Values

Declaring boolean variables.

public class Main {
  public static void main(String[] args) {
    boolean isJavaFun = true;
    boolean isFishTasty = false;
    System.out.println(isJavaFun);
    System.out.println(isFishTasty);
  }
}

Boolean Expression

Using comparison operators.

public class Main {
  public static void main(String[] args) {
    int x = 10;
    int y = 9;
    System.out.println(x > y); // returns true, because 10 is higher than 9
  }
}

Real Life Example

Checking if age allows voting.

public class Main {
  public static void main(String[] args) {
    int myAge = 25;
    int votingAge = 18;
    System.out.println(myAge >= votingAge);
  }
}

Test Your Knowledge

Java Quiz

No quiz available for this topic yet.