Boolean Data Types
The boolean data type represents a single bit of information and can hold only one of two possible values: true or false.
This data type is used for simple flags that track true/false conditions.
The default value of a boolean variable is false.
Syntax:
Source Code:
public class BooleanWithComparison {
public static void main(String[] args) {
int a = 10;
int b = 20;
// Using comparison operators
boolean isEqual = (a == b); //false
boolean isNotEqual = (a != b); //true
boolean isGreater = (a > b); //false
boolean isLess = (a < b); //true
boolean isGreaterOrEqual = (a >= b); //false
boolean isLessOrEqual = (a <= b); //true
// Printing the results
System.out.println("a == b: " + isEqual); //false
System.out.println("a != b: " + isNotEqual); //true
System.out.println("a > b: " + isGreater); //false
System.out.println("a < b: " + isLess); //true
System.out.println("a >= b: " + isGreaterOrEqual); //false
System.out.println("a <= b: " + isLessOrEqual); //true
// Using comparison in an if-statement
if (a < b) {
System.out.println("a is less than b.");
} else {
System.out.println("a is not less than b.");
}
}
}Result:
Watch the video:
Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

