Summary
In this chapter, we learned about how Java’s operators work and how they cooperate. In addition, we learned how to cast in Java.
Initially, we discussed two important properties relating to operators: precedence and associativity. We saw that precedence dictates how common terms are grouped. Associativity comes into play when the operators have the same order of precedence.
We then examined the operators themselves. We started by looking at unary operators, which have one operand such as the prefix/postfix increment/decrement operators, ++
and --
.
We then moved on to the arithmetic operators: +
, -
, *
, /
, and %
. We noted that integer division truncates. In addition, we discussed that any math operations involving int
types or smaller results in int
. Lastly, we discussed in detail how the +
operator works when one or both operands are strings. In these cases, a string append is performed.
Next, we discussed relational operators. The results of these operators...