Java Programming

4.2 Expression

Expressions perform operations on data and move data around. Some expressions will be evaluated for their results, some for their side effects, some for both.

An assignment expression has the following form.
variable-expression assignment-operator expression

The variable expression can be just the name of a variable, or it can be an expression that selects a variable using array indices. The value type of the right-hand-side expression must be compatible with the variable type.

An assignment expression is most often used for its side effect: it changes the value of the variable selected by the variable expression to the value of the expression on the right-hand side. The value of the assignment expression is the value that is assigned to the selected variable.

An expression can have three kinds of result:
1. a value, such as the result of: (4 * i)
2. a variable, such as the result of: i = 4
3. nothing (in the case of an invocation of a method declared as void)

In most common assignment expressions, the assignment operator is =. Then the assignment expression has the following form.
variable-expression = expression

The Java arithmetic and bitwise operators can be combined with = to form assignment operators.
For example, the += assignment operator indicates that the right-hand side should be added to the variable, and the *= assignment operator indicates that the right-hand side should be multiplied into the variable.

Download for more knowledge

https://play.google.com/store/apps/details?id=ab.java.programming

Leave a comment