2.6.8 - Equality Operators

There are two equality operators, == (equality operator) and != (nonequality operators). Equality operators are binary operators. Both of their operands may be

• boolean (or Boolean which is a wrapper class type of the primitive type boolean). In this case the equality operator is named "boolean equality".
• Reference type or null type. In this case the equality operator is named "object equality". We will introduce objects later.
• Numeric type. In this case the equality operator is named "numerical equality".

Equality operators have lower precedence order then the relational operators. The expression below,

```m > n == t< s

```

The relational sub-expressions are first evaluated and their resulting values are compared for equality, This expression is better written for eliminating all misunderstandings by using parenthesis for explicitly explaining the order of evaluation as:

```( m > n ) == ( t < s )

```

The returning type of the equaliy operators is always boolean.

2.6.8.1 - Boolean Equality Operators

In the boolean equality operator, when borh operands are true, the returning boolean value is true. Otherwise false will be returned. We can try with example shown below:

```package preliminary;
public class BooleanEquality {
public static void main(String[] args){
boolean firstControl= true;
boolean secondControl= true;
boolean result = (firstControl == secondControl);
System.out.println(" Result = "  +  result);
} // end main
} //end class BooleanEquality
```

The result of this program :

```Result = true

```

The boolean inequality opeator != returns false only when both of the operands are false or true. It will return false in all other cases. An example is given below:

```package preliminary;
public class BooleanInequality {
public static void main(String[] args){
boolean firstControl= true;
boolean secondControl= true;
boolean result = (firstControl != secondControl);
System.out.println(" Result = "  +  result);
} // end main
} //end class BooleanInequality
```

The result of this program :

```Result = false

```