i

JAVA Complete Course

Operators

Operators in java are symbols which perform concrete operation. In Java we have couple of different type of operators. Let’s visit the table of operators.

Java unary operator is one which requires only one operand. This kind of operations can be increasing or the value by one, decreasing of the value by one, negating the value. In unary operations there is difference between”++” operator placing. For example, if we have

int a = 5;

And we will write “++” operator, which means increasing value by one, at the end of the variable, it will take place after other calculation. Let’s see on example;

int a = 5;

int b = 7;

int c = a++ + b;

In this case, variable c will be calculated as sum of a and b, but after that calculation a will be increased by one. If after last statement (int c = a++ + b;) we will print a, result will be 6.

But let’s revisit second example:

int x = 11;

int y = 17;

int z = ++x + ++y;

The result will be 12 + 18 and will be 30, as first increasing operation will take place. Same happens with “--"operator.