Operators
Explore Java operators including arithmetic, assignment, compound assignment, increment/decrement, relational, and logical operators. Learn how to use these operators effectively to perform calculations, comparisons, and logical operations in your Java programs as part of the AP Computer Science A fundamentals.
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 |