5.4 Logical operators
Logical operators are used to boolean Linking values together. In contrast to the relational operators, which first produce truth values through comparisons, logical operators are used for further processing of truth values.
Java provides the basic operations AND, OR and NOT available and also offers the option of influencing the evaluation behavior of the operands. Unlike most other programming languages, Java provides the AND and OR operations in two different versions, namely with Short circuit evaluation or without.
In the short-circuit evaluation of a logical expression, a partial expression further to the right is only evaluated if it is still relevant for the result of the overall expression. If is already wrong in the expression, it will inevitably always be wrong, regardless of the result of. In this case, the short-circuit evaluation will no longer be evaluated. The same applies to the use of the OR operator.
The one also available in Java EXCLUSIVE-OR operator must of course always be evaluated in the long variant. Table 5.3 gives an overview of the logical operators.
|!||Logical NOT||! a returns false if a is true and true if a is false.|
|&&||AND with short-circuit evaluation||a && b returns true if both a and b are true. If a is already false, false is returned and b is no longer evaluated.|
|||||OR with short circuit evaluation||a || b returns true if at least one of the two expressions a or b is true. If a is already true, true is returned and b is no longer evaluated.|
|&||AND without short-circuit evaluation||a & b returns true if both a and b are true. Both sub-expressions are evaluated.|
||||OR without short circuit evaluation||a | b returns true if at least one of the two expressions a or b is true. Both sub-expressions are evaluated.|
|^||Exclusive-OR||a ^ b returns true if both expressions have a different truth value.|
Table 5.3: Logical operators
- What number is after a million
- What is macroevolution for children
- How many different IoT protocols are there
- How can I increase the hotel WiFi speed
- What are some good nicknames for Caitlyn
- What camera did Avedon use
- Will No Mans Sky be another spore
- Why did Apple make the iPhone
- Who created the educational standards
- Ultimately, is capitalism a failed economic experiment?
- Does the environment really change its cycle
- Where's Pikachu in Pokemon Red
- What are the properties of aluminum
- Why did you go to college
- FDR was a Freemason
- How could PayPal be improved?
- Sue debt collection agencies
- Has a friend of yours ever changed
- Frankincense is more dangerous than cigarette smoke
- Narcissists often compliment others
- What does fairness and justice mean
- What is your domain name registration
- What are data warehouse functions
- How do I avoid kidney problems
- Daenerys deserves a better death
- How do we improve government spending
- How is REST useful
- Which is better Triumph or Harley Davidson
- Parents should encourage childhood love in general
- Has anyone ever had a buddha experience
- Canada has missiles
- What is the best film for filmmakers
- Why should I be an ambassador