next up previous
Next: Definition of constants and Up: Unit 04 Previous: Increment and decrement operators

Expressions with side-effect and statements (optional)

Java uses the term expression to indicate two different notions:

Example:

While Java allows us to use both types of expressions without limitations, we will use expressions-with-side-effect only to form statements, and we will always avoid their use inside arithmetic expressions.

Example: The statement

x = 5 * (y = 7);
should be rewritten as follows:
y = 7;
x = 5 * y;

This distinction is motivated by the fact that expressions are an abstraction for the mathematical concepts of function and of function application, while expressions-with-side-effect (statements) are an abstraction for the concept of assignment, i.e., of the modification of a memory location of the program.


next up previous
Next: Definition of constants and Up: Unit 04 Previous: Increment and decrement operators