Arithmetic operators in Java

Arithmetic operators in Java

06 Sep 2025
Beginner
8.6K Views
15 min read
Learn with an interactive course and practical hands-on labs

Free Java Course With Certificate

In Java, arithmetic operators are used to perform basic mathematical operations on numeric values. They can be applied to all primitive number types, including byte, short, int, long, float, and double.

We learned the Types of Operators in the previous Java tutorial. In this Java tutorial, we'll explore the syntax, types, and examples of arithmetic operators in Java.  95% of Java newbies miss jobs without basic skills. Don’t lose out, Enroll now in our Free Java Training to start strong and land your dream role!

What are the Arithmetic Operators in Java?

Operators in Java, a Java toolkit, are being used as a symbol that performs various operations according to the code. Arithmetic operators are fundamental components of Java that empower developers to perform mathematical operations and manipulate numeric values within their programs. Arithmetic operators are symbols or characters that perform mathematical operations on numeric operands. The primary arithmetic operators in Java include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).

Syntax:

The syntax for using arithmetic operators in Java is straightforward:

result = operand1 operator operand2;

Here, operand1 and operand2 are numeric values or variables, and the operator is the arithmetic operator that defines the operation to be performed.

Read More -

Types of Arithmetic Operators

Arithmetic Operators in Java are particularly used for performing arithmetic operations on given data or variables. There are various types of operators in Java, such as

OperatorsOperations
+Addition
-Subtraction
xMultiplication
/Division
%Modulus

Types of Arithmetic Operators

1. Addition Operator (+)

The addition operator (+) is used to add two numeric values. It can be applied to variables, literals, or a combination of both.

Example

int a = 5;
int b = 3;
int sum = a + b;
System.out.println("Sum: " + sum);

In this example, the variables a and b are added, and the result is stored in the variable sum. The output will be Sum: 8.

2. Subtraction Operator (-)

The subtraction operator (-) is used to subtract the right operand from the left operand.

Example

int x = 10;
int y = 7;
int difference = x - y;
System.out.println("Difference: " + difference);

The output of this code will be Difference: 3.

3. Multiplication Operator

The multiplication operator (*) is used to multiply two numeric values.

Example

int p = 4;
int q = 6;
int product = p * q;
System.out.println("Product: " + product);

This code will output Product: 24.

4. Division Operator (/)

The division operator (/) is used to divide the left operand by the right operand. It performs floating-point division if the operands are of different numeric types.

Example

double numerator = 15.0;
int denominator = 3;
double result = numerator / denominator;
System.out.println("Result: " + result);
The output will be Result: 5.0.

5. Modulus Operator (%)

The modulus operator (%) returns the remainder of the division of the left operand by the right operand. It is particularly useful for tasks such as checking whether a number is even or odd.

Example

int num = 17;
int divisor = 5;
int remainder = num % divisor;
System.out.println("Remainder: " + remainder);
The output will be Remainder: 2.

6. Operator Precedence

It's important to understand the precedence of arithmetic operators. Multiplication, division, and modulus operations take precedence over addition and subtraction. Parentheses can be used to override the default precedence and explicitly define the order of operations.

Example

int result = 10 + 2 * 5;
System.out.println("Result: " + result);
In this example, multiplication is performed first, so the output will be Result: 20.

Read More - Java Programmer Salary In India

Example of Arithmetic Operators in Java

Let's bring it all together with a few examples in our Java Compiler:
 public class ArithmeticOperationsExample {
    public static void main(String[] args) {
        // Given values
        int a = 10;
        int b = 3;

        // Arithmetic operations
        int sum = a + b; // 13
        int difference = a - b; // 7
        int product = a * b; // 30
        double quotient = (double) a / b; // 3.333...
        int remainder = a % b; // 1

        // Displaying results
        System.out.println("Sum: " + sum);
        System.out.println("Difference: " + difference);
        System.out.println("Product: " + product);
        System.out.println("Quotient: " + quotient);
        System.out.println("Remainder: " + remainder);
    }
}

This Java program initializes two variables a and b with values 10 and 3, respectively. It then performs the specified arithmetic operations and prints the results to the console. The explicit casting (double) is used to ensure that the division results in a floating-point value.

Output

Sum: 13
Difference: 7
Product: 30
Quotient: 3.3333333333333335
Remainder: 1
Read More

Why they are so important:

  • Basic Building Block of Logic: You can't write meaningful programs without performing calculations. Arithmetic operators let you handle numbers efficiently.
  • Used in Real-World Applications: From calculating totals in billing systems to updating game scores or processing sensor data in IoT, arithmetic operations are everywhere.
  • Support for Problem Solving and Decision Making: You often need to compare values or compute results before making decisions (like if statements), and that usually involves arithmetic.
  • Works with Different Data Types: Arithmetic operators can be used with integers, floating-point numbers, characters (as ASCII), and more—making them highly flexible.
  • Foundation for Advanced Concepts: They are used in loops, algorithms, and data structures like arrays and matrices, where calculations are frequently required.

Common Mistakes to Avoid When Using Arithmetic Operators in Java

While arithmetic operators in Java are simple to use, beginners often make a few common mistakes. Understanding these will help you write accurate and bug-free programs.

1. Integer Division Confusion-In Java, if both operands are integers, division gives only the whole number (quotient) and discards the decimal part.

Example:

int a = 10, b = 3;
System.out.println(a / b);  // Output: 3 (NOT 3.33)

2. Not Using Parentheses Properly in Expressions-Without parentheses, Java follows operator precedence rules, which may not give the expected result.

Example:

int result = 10 + 5 * 2;     // Output: 20 (Multiplication happens first)

3. Using % (Modulus) Instead of / (Division)-Beginners often confuse the modulus operator % with division /./ gives the quotient, while % gives the remainder.

Example:

int a = 10, b = 3;
System.out.println(a / b);  // Output: 3 (Quotient)
System.out.println(a % b);  // Output: 1 (Remainder)
Summary
This was all about the types of arithmetic operators in Java. Arithmetic operators in Java are indispensable tools for performing mathematical computations in programs. From basic addition to complex calculations, understanding these operators is crucial for any Java developer.
95% of startups want full-stack Java pros. Don’t be left out—Enroll now in our Java Full Stack Course to become their top choice.

FAQs

Arithmetic operators in Java are symbols or characters used to perform mathematical operations on numerical values. The standard arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).

The addition operator (+) in Java is used to add two numeric values. It can be applied to variables, literals, or a combination of both. 

Yes, Java supports automatic type conversion (type casting) for certain operations. However, it's essential to be aware of potential loss of precision when working with different data types

The modulus operator (%) in Java returns the remainder of the division of the left operand by the right operand. It is often used to check for divisibility or to cycle through a range of values.

Parentheses can be used to control the order of operations and to make expressions more readable.

Take our Java skill challenge to evaluate yourself!

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.

GET FREE CHALLENGE

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

He is a renowned Speaker, Solution Architect, Mentor, and 10-time Microsoft MVP (2016–2025). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.
Our Courses
Live Training - Book Free Demo
Advanced Full-Stack Java Developer Certification Training Course
27 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Accept cookies & close this