Relational operators in Java are used to compare two values or variables. The result of a relational operation is always a boolean value: true or false.
if, while, and for statementsJava provides six relational operators:
== Equal to!= Not equal to> Greater than< Less than>= Greater than or equal to<= Less than or equal to
// Demonstrating relational operators in Java
class RelationalDemo {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a == b);
System.out.println(a != b);
System.out.println(a > b);
System.out.println(a < b);
System.out.println(a >= b);
System.out.println(a <= b);
}
}
Each comparison checks the relationship between a and b and prints either true or false based on the condition.
== for object comparison