The other mathematical shorthand operators which Java provides are the += (a = a + number), *=, and so on.

The complete list of operators can be obtained from here.

Answer from npinti on Stack Overflow
🌐
Jenkov
jenkov.com › tutorials › java › math-operators-and-math-class.html
Java Math Operators and Math Class
The - operator will replace the two values with the difference between the two values, just like with the + operator. You can create longer chains of subtractions and thus subtract more values from each other. Here is an example of subtracting two values from another in a single Java statement: ... This works for variables too. Remember, minus minus equals plus, just like in normal math.
🌐
DataCamp
datacamp.com › doc › java › java-operators
Java Operators
Java operators are special symbols that perform operations on variables and values. They are used to manipulate data and variables in expressions. Java provides a wide array of operators categorized into several types based on their functionality. ... Arithmetic operators are used to perform basic mathematical operations...
🌐
W3Schools
w3schools.com › java › java_operators_arithmetic.asp
Java Arithmetic Operators
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... Arithmetic operators are used to perform common mathematical operations.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-arithmetic-operators-with-examples
Java Arithmetic Operators with Examples - GeeksforGeeks
July 12, 2025 - This program demonstrates how to implement basic arithmetic operations using user input in Java. The Scanner class makes it easy to read user input from the console, and the basic arithmetic operations are performed using standard mathematical operators in Java.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › op1.html
Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
The Java programming language provides operators that perform addition, subtraction, multiplication, and division. There's a good chance you'll recognize them by their counterparts in basic mathematics.
🌐
IIT Kanpur
iitk.ac.in › esc101 › 05Aug › tutorial › java › nutsandbolts › arithmetic.html
Arithmetic Operators
The Java programming language supports various arithmetic operators for all floating-point and integer numbers. These operators are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo).
🌐
ScholarHat
scholarhat.com › home
Arithmetic operators in Java
September 6, 2025 - 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 (%).
Find elsewhere
Top answer
1 of 9
49

No, you can't do that in Java. The compiler needs to know what your operator is doing. What you could do instead is an enum:

public enum Operator
{
    ADDITION("+") {
        @Override public double apply(double x1, double x2) {
            return x1 + x2;
        }
    },
    SUBTRACTION("-") {
        @Override public double apply(double x1, double x2) {
            return x1 - x2;
        }
    };
    // You'd include other operators too...

    private final String text;

    private Operator(String text) {
        this.text = text;
    }

    // Yes, enums *can* have abstract methods. This code compiles...
    public abstract double apply(double x1, double x2);

    @Override public String toString() {
        return text;
    }
}

You can then write a method like this:

public String calculate(Operator op, double x1, double x2)
{
    return String.valueOf(op.apply(x1, x2));
}

And call it like this:

String foo = calculate(Operator.ADDITION, 3.5, 2);
// Or just
String bar = String.valueOf(Operator.ADDITION.apply(3.5, 2));
2 of 9
10

Method arguments in Java must be expressions. An operator by itself is not an expression. This is not possible in Java.

You can, of course, pass objects (maybe enum constants) that represents those operators, and act accordingly, but you can't pass the operators themselves as parameters.


Additional tips

Since you're just starting Java, it's best to ingrain these informations early on to ease your future development.

  • Method names starts with lowercase: calculate instead of Calculate
  • Variable names starts with lowercase: operator instead of Operator
  • Double is a reference type, the box for primitive type double.
    • Effective Java 2nd Edition, Item 49: Prefer primitive types to boxed primitives
  • Don't return "error...". Instead, throw new IllegalArgumentException("Invalid operator");

See also

  • Java Language Guide/Autoboxing
  • Java Lessons/Exceptions
  • Coding Conventions/Naming
    • Unfortunate typo in this document: How is this statement making sense? (Sun’s naming convention for Java variables)
🌐
W3Schools
w3schools.com › java › java_operators.asp
Java Operators
Operators Arithmetic Assignment Comparison Logical Precedence Code Challenge Java Strings · Strings Concatenation Numbers and Strings Special Characters Code Challenge Java Math Java Booleans
🌐
W3Resource
w3resource.com › java-tutorial › java-arithmetic-operators.php
Java Arithmetic Operators - w3resource
December 21, 2022 - Arithmetic operators are used in mathematical expressions. Arithmetic operators are +(addition) , -(subtraction), * (multiplication), / (division) and % (reminder). Java provides built-in short-circuit addition and subtraction operators.
🌐
Programiz
programiz.com › java-programming › operators
Java Operators: Arithmetic, Relational, Logical and more
Java instanceof Operator · Java if...else Statement · Java Math IEEEremainder() Operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while * is also an operator used for multiplication. Operators in Java can be classified ...
🌐
Tutorialspoint
tutorialspoint.com › java › java_basic_operators.htm
Java Operators
Java operators are the symbols that are used to perform various operations on variables and values. By using these operators, we can perform operations like addition, subtraction, checking less than or greater than, etc.
🌐
Tutorialspoint
tutorialspoint.com › home › java › java arithmetic operators examples
Java Arithmetic Operators Examples
September 1, 2008 - Java arithmetic operators are used to perform basic mathematical operations such as addition, subtraction, multiplication, and division. These operators work with numeric data types like int, float, double, and long.
🌐
Medium
beknazarsuranchiyev.medium.com › java-math-operators-and-special-operators-ca5d7a372a5a
Java Math Operators & Special Operators | by Beknazar | Medium
April 24, 2022 - Java Math Operators & Special Operators Addition. Subtraction. Multiplication Division Remainder Special operators Addition We perform addition by using + operator on numeric data types int num1 = …
🌐
Coderanch
coderanch.com › t › 568212 › java › arithmetic-operations-operator-stored-variables
doing arithmetic operations when the operator are stored as variables (Beginning Java forum at Coderanch)
February 22, 2012 - You have two choices: 1. Write some code that executes the appropriate code path based on the operator. That could be a series if if (oper.equals(...)) { ... } else if ... steps. Or it could be done using the Command Pattern, or it could be done using Java enums with each operator's enum value implementing the operation differently.
🌐
PW Skills
pwskills.com › blog › java developer › arithmetic operators in java with syntax
Arithmetic Operators In Java With Syntax
Ans. Arithmetic operators are vital in Java programming. They perform math operations and define expressions and formulas in programs. java has addition, subtraction, multiplication, division, and modulus operators.
Published   December 23, 2025
🌐
Scaler
scaler.com › topics › java › arithmetic-operators-in-java
Java Arithmetic Operators - Scaler Topics
February 26, 2024 - Arithmetic operators in Java perform mathematical calculations like addition, subtraction, multiplication, division, and modulus.
🌐
Developer.com
developer.com › dzone › coding › java › operator overloading in java
Java Math Operators and the Math Class in Java
May 31, 2023 - Operator overloading with Manifold brings expressive and intuitive mathematical notation to Java, enhancing code readability and simplicity. While Java doesn't natively support operator overloading, Manifold empowers developers to achieve similar functionality and use familiar operators in their code.
🌐
Study.com
study.com › computer programming › programming languages
Java: Arithmetic Operators | Study.com
December 14, 2023 - Java provides the four basic math operators, plus an additional one we call [the modulo operator]]. We'll get to that in a minute.