Java Relational Operators

The relational operators are used to check the relation between the two variables.

A list of relational operators used in Java language:

Assume two variables "a" and "b", having the value 50 and 100 respectively.

S.No. Operators Example Description
1. == (equal to) (a == b) is not true. It is used to check if the values of two operands are equal or not, if yes then condition becomes TRUE otherwise FALSE.
2. != (not equal to) (a != b) is true. It is used to check if the values of two operands are equal or not, if values are not equal then condition becomes TRUE otherwise FALSE.
3. < (less than) (a < b) is true. It is used to check if the value of left operand is less than the value of right operand, if yes then condition becomes TRUE otherwise FALSE.
4. > (greater than) (a > b) is not true. It is used to check if the value of left operand is greater than the value of right operand, if yes then condition becomes TRUE otherwise FALSE.
5. <= (less than or equal to) (a <= b) is true. It is used to check if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes TRUE otherwise FALSE.
6. >= (greater than or equal to) (a >= b) is not true. It is used to check if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes TRUE otherwise FALSE.

Relational Operators Example

The following program is a simple example that demonstrates the relational operators.


/**
 * 
 * @author JavaTportal Corporation
 *
 */
public class RelationalOperatorsExample {

	public static void main(String args[]) {
		int a = 50;
		int b = 60;

		System.out.println("a == b = " + (a == b));
		System.out.println("a != b = " + (a != b));
		System.out.println("a > b = " + (a > b));
		System.out.println("a < b = " + (a < b));
		System.out.println("b >= a = " + (b >= a));
		System.out.println("b <= a = " + (b <= a));
	}
}

Output

a == b = false
a != b = true
a > b = false
a < b = true
b >= a = true
b <= a = false


Next Concept Bitwise Operators