In Java we can create statements that are known as conditions. Conditions are anything that result in a boolean value (true or false). We will have more of a use for conditions later on when we move into more complex topics like control statements and for/while loops.
To create a condition we can use comparison operators. Below is a list of the most common comparison operators in Java. We use these operators to check for equivalence or relationships between values.
All of the operators shown above can be used to compare number (doubles and ints). Below are some examples.
The only comparison operator that is available to use on Strings is "==". However, it does not work as you might assume. This operators does not check if two string values are the same it checks if the string objects are the same. Now you may think I've just said the same thing twice but these two things are very different. It is difficult to explain this concept without an example but essentially you can think of the == operator checking if the two strings you compare are stored in the same variable.
Now this is useful to know but how can we properly compare strings? Well we need to use a method called .equals(). This method will compare string values not objects and will tell us if the two strings are equivalent.
CAPITALS MATTER, see in the example above how "hello" is not the same as "Hello".
Now that we know how to create conditions it is time to learn how to combine them. To combine conditions together and create what is known as a chained conditional we can use AND, OR and NOT. These allow us to create one large condition out of many smaller condition.
In java we use the symbols seen below to represent AND OR NOT.
AND: && - if both conditions are true, return true
OR: || - if at least one of the conditions is true, return true
NOT: ! - if the condition is false, return true.