ch03 - 3 Operators and Assignments CERTIFICATION OBJECTIVES...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
3 Operators and Assignments CERTIFICATION OBJECTIVES Java Operators Logical Operators Passing Variables into Methods Two-Minute Drill Q&A Self Test
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
I 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? CERTIFICATION OBJECTIVE 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 of these. Java operators produce new values from one or more operands (just so we’re all clear, the operands 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 creators ( including one whose last name is a mountain range in California) have been known to get a few of these wrong. Assignment Operators 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 no-brainer (technical term) assignments. You will, however, be tested on the trickier assignments involving complex expressions and 2 Chapter 3: Operators and Assignments
Background image of page 2
casting. We’ll look at both primitive and reference variable assignments. But before we begin, let’s back up and peek inside of a variable. What is a variable? How are the variable and its value related? Variables are just bit holders, with a designated type. You can have an int holder, a double holder, a Button holder, and even a String[] holder. Within that holder is a bunch of bits representing the value. For primitives, the bits represent a numeric value (although we don’t know what that bit pattern looks like for boolean , but we don’t care). A byte with a value of 6, for example, means that the bit pattern in the variable (the byte holder) is 00000110, representing the 8 bits.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/17/2009 for the course CMPE 126 taught by Professor Gpour during the Fall '07 term at San Jose State University .

Page1 / 65

ch03 - 3 Operators and Assignments CERTIFICATION OBJECTIVES...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online