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.
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.
Videos
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.
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
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).
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...
GeeksforGeeks
geeksforgeeks.org › java › operators-in-java
Java Operators - GeeksforGeeks
Logical Operators are used to perform "logical AND" and "logical OR" operations, similar to AND gate and OR gate in digital electronics. They have a short-circuiting effect, meaning the second condition is not evaluated if the first is false. ... import java.io.*; class Geeks { // Main Function public static void main (String[] args) { // Logical operators boolean x = true; boolean y = false; System.out.println("x && y: " + (x && y)); System.out.println("x || y: " + (x || y)); System.out.println("!x: " + (!x)); } }
Published November 12, 2025
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_arithmatic_operators_examples.htm
Java Arithmetic Operators Examples
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.
W3Resource
w3resource.com › java-tutorial › java-arithmetic-operators.php
Java Arithmetic Operators - w3resource
September 17, 2020 - 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.
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.
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:
calculateinstead ofCalculate - Variable names starts with lowercase:
operatorinstead ofOperator Doubleis a reference type, the box for primitive typedouble.- 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)
Vaia
vaia.com › java arithmetic operators
Java Arithmetic Operators: Examples & Order | Vaia
Java Arithmetic Operators are special symbols used in programming to perform mathematical operations on variables and values like addition (+), subtraction (-), multiplication (*), division (/), and modulus (%), which returns the remainder of a division. These operators are crucial in manipulating ...
Oracle
docs.oracle.com › javase › tutorial › java › data › beyondmath.html
Beyond Basic Arithmetic (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
September 19, 2024 - The Java programming language supports basic arithmetic with its arithmetic operators: +, -, *, /, and %. The Math class in the java.lang package provides methods and constants for doing more advanced mathematical computation.