A set of symbols is used to indicate the kind of operation to be performed on data. These symbols are called operators.
Consider the expression:
Z = X + Y;
The + symbol in the statement is called the Operator and the operation performed is addition. This
operation is performed on the two variables X and Y, which are called as Operands. The combination of both the operator and the operands, Z = X + Y, is known as an Expression.
Java provides several categories of operators and they are as follows:
The basic assignment operator is a single equal to sign, ‘=’. This operator is used to assign the value on its right to the operand on its left. Assigning values to more than one variable can be done at a time. In other words, it allows you to create a chain of assignments.Consider the following statements:
The value 3456 and ‘M’ are assigned to the variables, balance and gender.
Arithmetic operators manipulate numeric data and perform common arithmetic operations on the data. Operands of the arithmetic operators must be of numeric type. Boolean operands cannot be used, but character operands are allowed. The operators mentioned here are binary in nature that is, these operate on two operands, such as X+Y. Here, + is a binary operator operating on X and Y.
Unary operators require only one operand. They perform various operations such as incrementing/
decrementing the value of a variable by 1, negating an expression, or inverting the value of a boolean
lists the unary operators.
+ Unary plus - Indicates a positive value
- Unary minus - Negates an expression
++ Increment operator - Increments the value of a variable by 1
-- Decrement operator - Decrements the value of a variable by 1
! Logical complement operator - Inverts a boolean