Learn about arithmetic, relational, logical, and assignment operators.
Operators are special symbols that perform specific operations on one, two, or three operands and then return a result. Java provides a rich set of operators. Arithmetic operators are used for mathematical calculations: addition (`+`), subtraction (`-`), multiplication (`*`), division (`/`), and modulus (`%`), which gives the remainder of a division. Relational operators are used to compare two values, and they always result in a `boolean` value (`true` or `false`). These include equal to (`==`), not equal to (`!=`), greater than (`>`), less than (`<`), greater than or equal to (`>=`), and less than or equal to (`<=`). They are the core of decision-making in programs. Logical operators, logical AND (`&&`) and logical OR (`||`), are used to combine multiple boolean expressions. The AND operator returns `true` only if both operands are true, while the OR operator returns `true` if at least one operand is true. The logical NOT (`!`) operator inverts a boolean value. Assignment operators are used to assign values to variables. The basic assignment operator is `=`, but Java also provides compound assignment operators like `+=`, `-=`, `*=`, and `/=`, which combine an arithmetic operation with an assignment. For instance, `x += 5` is shorthand for `x = x + 5`. Finally, there are increment (`++`) and decrement (`--`) operators, which increase or decrease a variable's value by one. Understanding how these operators work and their precedence is essential for writing correct and concise Java code.