Home Segments Top Top Previous Next

90: Mainline

Most operators are binary operators; that is, they have two operands. In Java, those two operands are found on the immediate left and immediate right of the operator. Some operators, such as the negation operator, -, and unary plus operator, +, have just one operand, found on the immediate right of the operator. Such operators are unary operators.

You can always determine whether the - and + denote unary or binary operators by looking to see whether there is any literal, variable, or subexpression, to the immediate left. If there is, then - denotes subtraction and + denotes addition; otherwise, - denotes negation and + is handled as though it were not there at all.