Operators can be unary, binary, or ternary.
(1) Unary operators have 1 operand. For example, the increment operator "++" is a unary operator.
/** Unary operators, of type Unary.
*/
public static final int POS = ERRONEOUS + 1; // +
public static final int NEG = POS + 1; // -
public static final int NOT = NEG + 1; // !
public static final int COMPL = NOT + 1; // ~
public static final int PREINC = COMPL + 1; // ++ _
public static final int PREDEC = PREINC + 1; // -- _
public static final int POSTINC = PREDEC + 1; // _ ++
public static final int POSTDEC = POSTINC + 1; // _ --
/** unary operator for null reference checks, only used internally.
*/
public static final int NULLCHK = POSTDEC + 1;
(2) Binary operators have 2 operands. For example, the division operator "/" has 2 operands.
/** Binary operators, of type Binary.
*/
public static final int OR = NULLCHK + 1; // ||
public static final int AND = OR + 1; // &&
public static final int BITOR = AND + 1; // |
public static final int BITXOR = BITOR + 1; // ^
public static final int BITAND = BITXOR + 1; // &
public static final int EQ = BITAND + 1; // ==
public static final int NE = EQ + 1; // !=
public static final int LT = NE + 1; // <
public static final int GT = LT + 1; // >
public static final int LE = GT + 1; // <=
public static final int GE = LE + 1; // >=
public static final int SL = GE + 1; // <<
public static final int SR = SL + 1; // >>
public static final int USR = SR + 1; // >>>
public static final int PLUS = USR + 1; // +
public static final int MINUS = PLUS + 1; // -
public static final int MUL = MINUS + 1; // *
public static final int DIV = MUL + 1; // /
public static final int MOD = DIV + 1; // %
/** Assignment operators, of type Assignop.
*/
public static final int BITOR_ASG = MOD + 1; // |=
public static final int BITXOR_ASG = BITOR_ASG + 1; // ^=
public static final int BITAND_ASG = BITXOR_ASG + 1; // &=
public static final int SL_ASG = SL + BITOR_ASG - BITOR; // <<=
public static final int SR_ASG = SL_ASG + 1; // >>=
public static final int USR_ASG = SR_ASG + 1; // >>>=
public static final int PLUS_ASG = USR_ASG + 1; // +=
public static final int MINUS_ASG = PLUS_ASG + 1; // -=
public static final int MUL_ASG = MINUS_ASG + 1; // *=
public static final int DIV_ASG = MUL_ASG + 1; // /=
public static final int MOD_ASG = DIV_ASG + 1; // %=
(3) The ternary operator has 3 operands. For example, the conditional operator "?:" has 3 operands.
The behavior of the operator may also vary depending on the number of operands provided. The subtraction operator "-" is both unary and binary. For the subtraction operator, if only one operand is supplied,
the operator negates the operand and returns the result; if two operands are supplied, the subtraction operator returns the difference of the two operands.