Java Operators

Operators perform operations on operands like variables or values.

In Java, there are five types of operators based on the type of operations they perform. They are

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators

Arithmetic Operators

Java Arithmetic Operators perform mathematical arithmetic operations and return the result. Following are the arithmetic operators supported in Java.

OperatorNameDescription
+AdditionReturns the sum of two operands.
SubtractionReturns the difference of right operand from left operand.
*MultiplicationReturns the product of left and right operand.
/DivisionReturns the division of left operand with right operand.
%Modulus DivisionReturns the reminder when left operand is divided by right operand.
++IncrementIncrements the operand by 1.
DecrementDecrements the operand by 1

Addition

Java Program

public class OperatorExample {
	public static void main(String[] args) {
		int a = 8;
		int b = 3;
		
		int c = a + b;
		System.out.print(c);
	}
}

Output

11

More about Java Addition Operator.

Subtraction

Java Program

public class OperatorExample {
	public static void main(String[] args) {
		int a = 8;
		int b = 3;
		
		int c = a - b;
		System.out.print(c);
	}
}

Output

5

More about Java Subtraction Operator.

Multiplication

Java Program

public class OperatorExample {
	public static void main(String[] args) {
		int a = 8;
		int b = 3;
		
		int c = a * b;
		System.out.print(c);
	}
}

Output

24

More about Java Multiplication Operator.

Division

Java Program

public class OperatorExample {
	public static void main(String[] args) {
		int a = 8;
		int b = 3;
		
		int c = a / b;
		System.out.print(c);
	}
}

Output

2

More about Java Division Operator.

Modulus Division

Java Program

public class OperatorExample {
	public static void main(String[] args) {
		int a = 8;
		int b = 3;
		
		int c = a % b;
		System.out.print(c);
	}
}

Output

2

More about Java Modulus Operator.

Increment

Java Program

public class OperatorExample {
	public static void main(String[] args) {
		int a = 8;
		
		int c = ++a;
		System.out.print(c);
	}
}

Output

9

More about Java Increment Operator.

Decrement

Java Program

public class OperatorExample {
	public static void main(String[] args) {
		int a = 8;
		
		int c = --a;
		System.out.print(c);
	}
}

Output

7

More about Java Decrement Operator.