It's been about a month or so since we finished our beginning Java series, so I'm sure you're ready for more. This time, I am going to teach you to work with operators in Java. When I am finished, you will be able to do complex mathematical equations, add one string of text to another, and build programs so powerful you will be able to put thousands of hard working Americans out of work with the push of a button.
There used to be a time when you called "Information" on the phone and you heard a real, honest-to-goodness voice. All that is done with. Now you talk to a computer, and the funny thing about computers is that they have no ears. So when I call up and, for example, ask for the number to Annie's Pizza, it's little surprise that the “operator” comes back to me with the number to Danny's Pizza, no matter how much emphasis I place on the A in Annie.
Unlike modern computer operators, Java Operators aren't annoying, and like the phone operators of old, are actually helpful. You have used operators your entire life, and their function is simple: they allow you to manipulate data. And let's face it, what good is data if you can't manipulate it?
There are several types of operators, but before we go into them, you should understand a little thing we in the biz call operator precedence. Precedence determines in which order operators execute. If that's not clear, it will be in a few moments.
But first, look at this beautiful table designed by yours truly:
++expr –expr +expr -expr ~ !
* / %
<< >> >>>
< > <= >= instanceof
bitwise exclusive OR
bitwise inclusive OR
“=” += -= *= /= %= &= ^= |= <<= >>= >>>=
The above table lists the operators and their precedence in order.