Relational and logical operators

Relational operators are used to compare values with each other. They return a logical result: true or false. Values that are linked with relational operators are called elementary statements in propositional logic.
A typical example of a Boolean logical operator is the and operation: It always returns true if all operands are also true.

OperatorDescriptionPriority
<smaller5
<=less than or equal to5
>greater5
>=greater than or equal to5
==equal6
!=unequal6
!expression is false1
&&both expressions are true10
||at least one expression is true11

Example

public class RelationalLogicalExpressions {
	public static void main(String[] args) {
		int a = 0, i = 20, b = 8;
		while (a != b && i >= a + b) {
			System.out.println(a + " is unequal " + b);
			a++;
		}
		System.out.println(a + " is equal " + b);
	}
}
Output
0 is unequal 8
1 is unequal 8
2 is unequal 8
3 is unequal 8
4 is unequal 8
5 is unequal 8
6 is unequal 8
7 is unequal 8
8 is equal 8