E and PI are not functions, they're static fields (data members). That code will output their values correctly. You don't have to import anything, the Math class is in the java.lang package, which is imported by default. (It's the only package imported by default, I believe.)

Answer from T.J. Crowder on Stack Overflow
๐ŸŒ
GitHub
github.com โ€บ TilmanNeumann โ€บ java-math-library
GitHub - TilmanNeumann/java-math-library: A Java math library focused on number theory and integer factorization in particular.
A Java math library focused on number theory and integer factorization in particular. - TilmanNeumann/java-math-library
Starred by 33 users
Forked by 8 users
Languages ย  Java 100.0% | Java 100.0%
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ java_lang_math.htm
Java - Math Class
The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
Discussions

java - Should I import a math library, and if so how? - Stack Overflow
I think I have to import the math library. ... E and PI are not functions, they're static fields (data members). That code will output their values correctly. You don't have to import anything, the Math class is in the java.lang package, which is imported by default. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Java math libraries?
Apache Math has a polynomial fitter. It also has a linear solver and lots of other useful bits. I haven't used a symbolic math solver in Java. It's not quite the same, but I did use Z3 with Java this year, there is z3-turnkey that provides a helpful Maven dependency for that. More on reddit.com
๐ŸŒ r/adventofcode
4
8
December 26, 2023
What is the best math library to use with java? - Stack Overflow
I want to use math functions for data mining and analytics purpose. I need an opinion about a library that I can use for this purpose with java. Do you have any recommendations? More on stackoverflow.com
๐ŸŒ stackoverflow.com
I need a Java library that simplifies math equations - Software Recommendations Stack Exchange
let's say, for example, I give this equation as an input: 4x + x - 20 + 10 And I want to get 5x - 10 as a result More on softwarerecs.stackexchange.com
๐ŸŒ softwarerecs.stackexchange.com
๐ŸŒ
Jenkov
jenkov.com โ€บ tutorials โ€บ java โ€บ math-operators-and-math-class.html
Java Math Operators and Math Class
Java contains a set of built-in math operators for performing simple math operations on Java variables. The Java math operators are reasonably simple. Therefore Java also contains the Java Math class which contains methods for performing more ...
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ lang โ€บ Math.html
Math (Java Platform SE 8 )
October 20, 2025 - Javaโ„ข Platform Standard Ed. 8 ... The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_math.asp
Java Math
The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
๐ŸŒ
Apache Commons
commons.apache.org โ€บ math
Commons Math: The Apache Commons Mathematics Library
Apache Commons, Apache Commons Math, Apache, the Apache feather logo, and the Apache Commons project logos are trademarks of The Apache Software Foundation.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ beginners-guide-to-java-math-21edc9cc1ee0
Java Math Guide for Beginners | Medium
March 9, 2024 - As we go deeper into Javaโ€™s mathematical capabilities, we encounter the Math classโ€”a powerful library that Java offers for performing a wide array of mathematical operations beyond basic arithmetic. The Math class is part of the java.lang package, which means it is automatically available and does not require an import statement.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-math-class
Java Math Class - GeeksforGeeks
July 23, 2025 - Let us check the method provided in the Math class. ... // Java program to demonstrate the // Use of Math Class public class MathLibraryExample { public static void main(String[] args) { int i = 7; int j = -9; double x = 72.3; double y = 0.34; System.out.println("i is " + i); System.out.println("j is " + j); // The absolute value of a number is equal to the // number if the number is positive or zero and // equal to the negative of the number if the number // is negative.
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ java-math-library
Java Math Library
March 28, 2025 - The Java Math Library provides various Functions & Properties and allows basic mathematical functionality like square root, cbrt, etc.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-import-a-math-class-in-Java
How to import a math class in Java - Quora
Java provides math-related functionality through the java.lang.Math and java.math packages.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ java-math-class
Math Class in Java & Methods (with Examples)
October 9, 2023 - When it comes to performing mathematical operations in Java, you have the option to use the built-in Math class or third-party libraries specifically designed for mathematical computation, such as Apache Commons Math or JAMA.
๐ŸŒ
Reddit
reddit.com โ€บ r/adventofcode โ€บ java math libraries?
r/adventofcode on Reddit: Java math libraries?
December 26, 2023 -

One thing I learned this year is that maybe I should figure out how to use some math libraries/packages.

There are two problems that I ended up using a little outside help with. One was doing a polyfit. Especially, I have a list of input values and output results and I want the computer to tell me a function that matches. This is good for things where I'm sure there is a simple math relation, I just can't see it. For example in one problem, I had a series of numbers and needed polyfit to tell me I was actually looking at 5 + 2x + x^2 or something like that.

I ended up using python and numpy for that, which worked but I'd like to add that sort of capability to my Java tool kit.

The other, I kinda worked around but it would be nice to have is a symbolic math solver.

I've poked at Symja which has a enticing named solver:
https://bitbucket.org/axelclk/symja_android_library/wiki/Solve

But I'm having trouble getting the dependencies to run. Anyone have anything they like?

In case it matters, I'm using bazel to build, which means I can easily include anything that is on maven.

๐ŸŒ
Java Almanac
javaalmanac.io โ€บ jdk โ€บ 1.2 โ€บ api โ€บ java โ€บ lang โ€บ Math.html
Java Platform 1.2 API Specification: Class Math
The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. To help ensure portability of Java programs, the definitions of many of the numeric functions in this package require that they produce ...
๐ŸŒ
Maven Repository
mvnrepository.com โ€บ open-source โ€บ math-libraries
Maven Repository: Math Libraries
Alternate implementations of JDK's "Math" functions. ... A fast and easy to use dense and sparse matrix linear algebra library written in Java.
๐ŸŒ
jmathanim
davidgutierrezrubio.github.io โ€บ jmathanim
jmathanim | A Java library to make mathematical animations
JMathAnim is a library written in JAVA to simplify the process of creating mathematical animations. mathematical animations.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_ref_math.asp
Java Math Reference
The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
Top answer
1 of 3
1

You can use the Symja - Java computer algebra and symbolic math library.

import org.matheclipse.core.eval.ExprEvaluator;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.core.interfaces.ISymbol;
import org.matheclipse.parser.client.SyntaxError;

public class Example {
  public static void main(String[] args) {
    try {
      ExprEvaluator util = new ExprEvaluator(false, (short) 100);

      // Convert an expression to the internal Java form:
      // Note: single character identifiers are case sensitive
      // (the "D()" function identifier must be written as upper case character)
      String javaForm = util.toJavaForm("4*x + x - 20 + 10");
      // prints: Plus(ZZ(-20L),x,Times(C4,x),C10)
      System.out.println("Out[1]: " + javaForm.toString());

      // Use the Java form to create an expression with F.* static methods:
      ISymbol x = F.Dummy("x");
      IAST function = F.Plus(F.ZZ(-20L), x, F.Times(F.C4, x), F.C10);
      IExpr result = util.eval(function);
      // print: -10+5*x
      System.out.println("Out[2]: " + result.toString());
    } catch (SyntaxError e) {
      // catch Symja parser errors here
      System.out.println(e.getMessage());
    } catch (RuntimeException rex) { 
      System.out.println(rex.getMessage());
    }
  }
}
2 of 3
0

DataMelt (http://jwork.org/dmelt) does this. Here is an example (I use Jython, but you can use Java too)

from jhplot.math import *  
from jhplot import *
j=Symbolic("jscl") # using jscl engine
print j.simplify("(x + 1)^(1/x)") == "(1+x)^(1/x)" 
print j.simplify("(x^2-1)/(x-1)") == "1+x"

This code returns "true" for all such simplifications