Conditional, Equality and Relational Operators in Java

Conditional, Equality and Relational operators in Java are used to compare the value between variables, and also between expressions. When a condition is evaluated, it always results in a value of data type boolean, in other words, true or false.

What are the Equality and Relational operators in Java?

  • The equality and relational operators determine if one operand (for example a variable) is greater than, less than, equal to, or not equal to another stated operand
  • The result when comparing two variables is a boolean, which means that true is returned if the expression is true and false if the expression is false.
  • Note, we must use two equal signs “==” when comparing if operands are equal

 

Moreover, the equality and relational operators are certainly not unique to programming in Java, and are widely known in mathematics. Further down on this page, we show a few straightforward exercises that can be good to repeat as we will continue to use equality and relational operators frequently.

What are the Conditional operators in Java?

  • The conditional operators, AND together with OR, compares two expressions.
  • The result when comparing two expressions is a boolean, which means that true is returned if the expression is true and false if the expression is false.

 

Furthermore, similar to the equality and relational operators, the conditional operators are certainly not unique to programming in Java. Further down on this page, we show a few straightforward exercises that can be good to repeat as we will continue to use the conditional operators frequently.

Conditional, Equality and Relational Operators in Java

 

Name Syntax Description
AND  a && b True if a and b are true
OR a || b True if  a or b are true
NOT !a True if a is false
Equal to a == b True if a and b are equal
Not equal to a != b True if a are false and b are false
Greater than a > b True if a are greater than b
Less than a < b True if a are less than b
Less than or equal to a <= b True if a is smaller or as large as b
Greater than or equal to a >= b True if a is larger or as large as b

EXERCISE

Let’s take an exercise so that we can test how some conditional, equality, and relational operators in Java work. The task is to fill in the spaces in the boxes with True or False depending on the expression. Given in the task is that: a = 10 and that b = 20.

Conditional, Equality and Relational operators in Java
Solution
Conditional, Equality and Relational operators in Java - Answers

More information about the Conditional, Equality and Relational operators in Java is available at the Oracle website