JavaOperators Overview

Operators Overview

Operators are the symbols Java uses to perform computations, compare values, combine boolean logic, manipulate bits, and assign results to variables. Almost every line of real Java code uses at least one. This page is a map of every operator category — each row links conceptually to a deeper dedicated page where that category is covered in full.

Category

Purpose

Example

Arithmetic

Basic math: add, subtract, multiply, divide, remainder.

int sum = a + b;

Relational (Comparison)

Compare two values and produce a boolean result.

if (age >= 18) { ... }

Logical

Combine or invert boolean expressions.

if (isAdult && hasId) { ... }

Bitwise

Operate on the individual bits of integer values.

int flags = a & b;

Assignment

Store a value into a variable, optionally combined with an operation.

total += price;

Ternary

A compact inline if-else that produces a value.

int max = (a > b) ? a : b;

Arithmetic Operators

Java provides the five standard arithmetic operators: + (addition), - (subtraction), * (multiplication), / (division), and % (remainder/modulo). Division between two integers performs integer division (discarding the fractional part), which surprises many beginners the first time they see 7 / 2 evaluate to 3 rather than 3.5.

Relational Operators

Relational operators — ==, !=, >, <, >=, <= — compare two values and always produce a boolean (true or false). They’re the backbone of every if statement and loop condition.

Logical Operators

Logical operators — && (AND), || (OR), and ! (NOT) — combine or invert boolean expressions, letting you express conditions like “the user is an adult and has a valid ID.” Java’s && and || are short-circuiting: if the left side already determines the result, the right side is never evaluated.

Bitwise Operators

Bitwise operators (&, |, ^, ~, <<, >>, >>>) work directly on the binary representation of integer values. They’re less common in everyday application code but essential for tasks like working with flags, low-level protocols, and performance-sensitive numeric code.

Assignment Operators

The plain assignment operator = stores a value in a variable. Java also offers compound assignment operators (+=, -=, *=, /=, %=, and bitwise equivalents) that combine an operation with an assignment in one step:

Java
int total = 100;
total += 25;   // same as: total = total + 25;
total -= 10;   // same as: total = total - 10;
The Ternary Operator

The ternary operator ?: is Java’s only operator that takes three operands. It works as a compact inline if-else that evaluates to a value rather than executing a block of statements:

Java
int a = 10, b = 20;
int max = (a > b) ? a : b;
System.out.println(max); // 20
Note
Each of these categories has its own dedicated page with full details, more examples, precedence rules, and common pitfalls — this page exists to give you the big picture before diving into any one of them.