f you’ve got variables, you’re going to modify them. You’ll increment them, add them
together, shift their bits, flip their bits, and compare one to another. In this chapter you’ll
learn how to do all that in Java. We’ll end the chapter exploring the effect of passing
variables of all types into methods. For an added bonus, you’ll learn how to do things that you’ll
probably never use in the real world, but that will almost certainly be on the exam. After all,
what fun would it be if you were tested only on things you already use?
Java Operators (Exam Objective 5.1)
Determine the result of applying any operator (including assignment operators and
instanceof) to operands of any type, class, scope, or accessibility, or any combination
produce new values from one or more
(just so we’re all clear,
are things on the right or left side of the operator). The result of most
operations is either a boolean or numeric value. And because you know by now that
Java is not C++
, you won’t be surprised that Java operators can’t be overloaded.
There is, however, one operator that comes overloaded out of the box: If applied to a
String, the + operator concatenates the right-hand operand to the operand on the left.
Stay awake. The operators and assignments portion of the exam is typically the
one where exam takers see their lowest scores. We aren’t naming names or anything,
but even some of the exam
including one whose last name is a mountain
range in California) have been known to get a few of these wrong.
Assigning a value to a variable seems straightforward enough; you simply assign the
stuff on the right side of the = to the variable on the left. Well, sure, but don’t expect
to be tested on something like this:
x = 6;
No, you won’t be tested on the
(technical term) assignments. You will,
however, be tested on the trickier assignments involving complex expressions and
Operators and Assignments