Search⌘ K

Logical Expressions

Explore logical expressions in Java by understanding comparative and boolean operators. This lesson helps you evaluate conditions using operators like AND, OR, NOT, and comparison symbols, enabling you to write clear and accurate boolean logic in Java code.

Introduction

Logical expressions are also known as Boolean expressions. It will always evaluate to a value of either true or false. Therefore, they will be represented by the data type boolean. While they may seem similar to mathematical operators, the difference lies in how they are used with comparative or boolean operators. Let’s look at both types of operators in detail.

Comparative operators

Java has several operators that can be used to compare value. Comparison implies knowing which value is greater than the other, or equal to it, and so on. The table below shows the entire list of operators available in Java.

Symbols Comparative operators
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to

Note here that these comparative operators can be used on any primitive data type except for boolean.

Now that we have ...