|Lesson 9||Using Java's Boolean, string, and assignment operators|
|Objective||Examine Boolean, string, and assignment operators in Java.|
Java Boolean, String, Assignment Operators
Java also supports a number of Boolean, string, and assignment operators.
Boolean operators are used to perform logical comparisons, and always result in one of two values: true or false.
Following are the most commonly used Boolean operators:
- AND: Compares two values and returns true if they are both true
- OR: Compares two values and returns true if either of the values are true
- Negation: Flips the state of a value
- Equal-to: Compares two values for equality
- Not-equal-to: Compares two values for inequality
Java Boolean Operators
There is only one string operator, the concatenation operator (+), which appends a string onto another string. Following is an example of using the concatenation operator:
String nickname = "tough guy";
String message = "Hey there, " + nickname + "!";
The nickname string is effectively placed in the middle of a sentence. This code acts somewhat like a form letter in that you provide a sentence and then plug a name into it.
Assignment operators all perform some type of operation that results in a value being stored in a variable.
The following link contains the most commonly used assignment operators:
prime Application - Exercise