10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER15<br />

Expressions<br />

When you can measure what you are speaking about,<br />

and express it in numbers, you know something about it;<br />

but when you cannot measure it, when you cannot express it in numbers,<br />

your knowledge of it is of a meager and unsatisfactory kind:<br />

it may be the beginning of knowledge, but you have scarcely,<br />

in your thoughts, advanced to the stage of science.<br />

—William Thompson, Lord Kelvin<br />

MUCH of the work in a program is done by evaluating expressions, either for<br />

their side effects, such as assignments to variables, or for their values, which can<br />

be used as arguments or operands in larger expressions, or to affect the execution<br />

sequence in statements, or both.<br />

This chapter specifies the meanings of expressions and the rules for their evaluation.<br />

15.1 Evaluation, Denotation, and Result<br />

DRAFT<br />

When an expression in a program is evaluated (executed), the result denotes one<br />

of three things:<br />

• A variable (§4.12) (in C, this would be called an lvalue)<br />

• A value (§4.2, §4.3)<br />

• Nothing (the expression is said to be void)<br />

Evaluation of an expression can also produce side effects, because expressions<br />

may contain embedded assignments, increment operators, decrement operators,<br />

and method invocations.<br />

An expression denotes nothing if and only if it is a method invocation<br />

(§15.12) that invokes a method that does not return a value, that is, a method<br />

409

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!