In lessons 3 through 5, we learned how to declare and initialize variables. So now we want to apply that knowledge and move forward. Moving forward we need to learn about Operators in the Java programming language. So what is an Operator?

Operators are special symbols that each perform a specific operation on operands, which returns some sort of a result. An operand is the object that is being manipulated by an Operator.

In the Java programming language, each operators has a precedence order. The operators in the table below are listed according to their precedence order. The operators at the top of the table have a higher precedence.

Operators with a higher precedence are evaluated before operators below them on the table. Operators on the same line all have the same precedence. When operators of the same precedence appear in the same expression, a rule must govern which is evaluated first.

All binary operators, excluding the assignment operators, are evaluated from left to right. The assignment operators are evaluated right to left. I know, it gets a little tricky.

By far the most commonly used assignment operator is “=”. I also tend to use the logical AND ( && ) and logical OR ( || ) quite a bit in my Java development.

Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=

Now that your done with lesson 6, be sure to move onto the next lesson.

Add a Comment

Your email address will not be published. Required fields are marked *