15
C H A P T E R
Expressions
When you can measure what you are speaking about,
and express it in numbers, you know something about it;
but when you cannot measure it, when you cannot express it in numbers,
your knowledge of it is of a meager and unsatisfactory kind:
it may be the beginning of knowledge, but you have scarcely,
in your thoughts, advanced to the stage of science.
William Thompson, Lord Kelvin
M
UCH of the work in a Java program is done by evaluating
expressions
, either
for their side effects, such as assignments to variables, or for their values, which
can be used as arguments or operands in larger expressions, or to affect the execu
tion sequence in statements, or both.
This chapter specifies the meanings of Java expressions and the rules for their
evaluation.
15.1 Evaluation, Denotation, and Result
When an expression in a Java program is
evaluated
(
executed
), the
result
denotes
one of three things:
A variable ( 4.5) (in C, this would be called an
lvalue
)
A value ( 4.2, 4.3)
Nothing (the expression is said to be
void
)
Evaluation of an expression can also produce side effects, because expres
sions may contain embedded assignments, increment operators, decrement opera
tors, and method invocations.
An expression denotes nothing if and only if it is a method invocation
( 15.11) that invokes a method that does not return a value, that is, a method
301
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved