Operators
Let's look at some common types of operators in Java.
Operators are used to perform certain operations on variables and values. For example, addition (+) and subtraction (-) are both operators.
Java offers a number of different operators for different data types. Based on their functions, we can divide operators into the following categories:
- Arithmetic operators
- Assignment operator
- Compound assignment operators
- Increment and decrement operator
- Relational operators
- Logical operators
Let’s discuss them one by one.
Arithmetic operators
These are the kind of operators that we use in simple mathematical equations involving integers and decimal numbers. We will go into the details about these operators in the next lesson. For now, the following table summarizes different arithmetic operators.
Operator | Function | Example |
---|---|---|
+ |
Addition | 9 + 2 results in 11 |
- |
Subtraction | 9 - 2 results in 7 |