Site icon TestingDocs.com

Java Conditional Operators

Overview

In this tutorial, we will learn Java Conditional Operators. Conditional operators are also called as logical operators. These operators operate on boolean expressions.

Conditional Operators

Conditional Operation
Operator Symbol  Example
Logical AND

 

&& booleanExp1 && booleanExp2
Logical OR || booleanExp1 || booleanExp2
Ternary Operator ?:

 

The logical AND operator evaluates to true if both the boolean expressions are true, otherwise evaluates to false.

The logical OR operator evaluates to false if both the boolean expressions are false, otherwise evaluates to true.

The ternary operator uses three operands. It evaluates a boolean expression and if the boolean expression is true, the second operand is returned , otherwise, it returns the third operand.

For example:

output = booleanExp ? value1 : value2 ;

If the booleanExp evaluates to true the value1 is assigned to output variable. If the booleanExp evaluates to false the value2 is assigned to output variable.

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Exit mobile version