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
🌐
Linux Hint
linuxhint.com › import-math-in-java
How to Import Math in Java? – Linux Hint
To import Math in Java, you can use the “java.lang” package to access the methods or variables of the Java Math class with their class name. Another way to import a Math class is to add the “java.lang.Math.*” import statement at the top of the code. It will allow access to all the members ...
🌐
JavaBeat
javabeat.net › home › how to import math in java?
How to Import Math in Java?
March 13, 2024 - To import the Math class in Java, use the “import static java.lang.Math.*;” statement at the start of your Java program.
Discussions

java - Should I import a math library, and if so how? - Stack Overflow
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
In Java, you cannot import single methods from a class, so how would I do it in my language?
It's always legal to use the fullly qualified name of something instead of importing it in Java source code, like java.lang.System.out.println(libraries.standard.READ_LINE). JVM bytecode also does not have an "import" concept and always refers to things by their fully qualified names. If you'd like to compile to Java source code, you could first compile to an intermediate Java abstract syntax tree that always refers to things with their fully qualified names, then as one of the last operations iterate over the tree, hoisting as many names into import statements as you can. (Sortof the reverse operation of "name resolution" which is one of the first things a compiler does.) So basically this is a code formatting question. Note that Java source does not allow importing two things with the same name, so in some cases you won't be able to hoist all the imports. That's ok. More on reddit.com
🌐 r/ProgrammingLanguages
25
6
March 9, 2024
How do I use/import the Apache Commons Math Java library?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
4
1
January 19, 2025
How come I didn't need to import java.lang.Math for my code?

java.lang is always imported by default for Java.

More on reddit.com
🌐 r/learnjava
8
2
January 24, 2015
🌐
TutorialsPoint
tutorialspoint.com › static-import-the-math-class-methods-in-java
Static import the Math Class Methods in Java
July 30, 2019 - import static java.lang.Math.sqrt; public class Demo { public static void main(String[] arg) { double num = 36.0; System.out.println("The number is: " + num); System.out.println("The square root of the above number is: " + sqrt(num)); } } The number is: 36.0 The square root of the above number is: 6.0 · Now let us understand the above program. The Math class is not required along with the method sqrt() as static import is used for the java.lang package.
🌐
W3Schools
w3schools.com › java › java_math.asp
Java Math
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 ... The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
🌐
FavTutor
favtutor.com › blogs › java-math-class
Math Class in Java & Methods (with Examples)
October 9, 2023 - Understand everything about the Math class in Java, its methods how to import it, and examples to use the Math class.
Find elsewhere
🌐
Quora
quora.com › How-do-I-import-a-math-class-in-Java
How to import a math class in Java - Quora
java.math.BigInteger and BigDecimal: require explicit import (they are in java.math).
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api
Math (Java Platform SE 8 )
October 20, 2025 - JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-math-class-java-set-2
Java.lang.Math Class in Java | Set 2 - GeeksforGeeks
July 23, 2025 - ... // Java program explaining lang.Math class methods // exp(), decrementExact(), cosh() import java.math.*; public class NewClass { public static void main(String[] args) { // Use of cosh() method double value = 2; double coshValue = ...
🌐
Educative
educative.io › answers › how-to-use-the-mathrandom-method-in-java
How to use the Math.random() method in Java
import java.lang.Math; //importing Math class in Java ... System.out.println("Random Number: " + rand); // Output is different everytime this code is executed ... Mostly the random() method is used to generate random numbers between a specific range.
🌐
Jenkov
jenkov.com › tutorials › java › math-operators-and-math-class.html
Java Math Operators and Math Class
This Java math tutorial explains both the basic Java math operators as well as the more advanced Java Math class.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-class
Java Math Class - GeeksforGeeks
July 23, 2025 - // 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.
🌐
Study.com
study.com › courses › business courses › business 104: information systems and computer applications
How to Use Pi Constant in Java - Lesson | Study.com
January 15, 2018 - The import code looks like this: ... Even though pi goes on seemingly forever, Java stores the value of pi as a constant, or 3.141592653589793. For programming purposes, this is precise enough. Normally we don't like the term 'good enough' in mathematics, but we can't have infinite values in our Java variables.
🌐
Android Developers
developer.android.com › api reference › math
Math | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
JanBask Training
janbasktraining.com › community › java › should-i-import-a-math-library-and-if-so-how
Should I import a math library, and if so how? | JanBask Training Community
August 6, 2025 - The math library deals with real numbers (not complex). For complex math, use the cmath module. All functions in the module expect and return float values.
🌐
Reddit
reddit.com › r/programminglanguages › in java, you cannot import single methods from a class, so how would i do it in my language?
r/ProgrammingLanguages on Reddit: In Java, you cannot import single methods from a class, so how would I do it in my language?
March 9, 2024 -

Hey y'all, I'm writing a transpiled language, which, you guessed it, transpiles to Java.

Now, I was planning on doing a import statement like this:

incorp standard {
print_line,
read_line,
STD_SUCCESS,
STD_FAILURE

}

which would transpile to something like this:

import libraries.standard;
import libraries.standard.STD_FAILURE; 
import libraries.standard.print_line; 
import libraries.standard.read_line; 

Problem is, I found out that you can't actually import a single method from a class in Java, so how would I go about fixing the problem? One solution I thought about would be that when importing a single function, it actually transpiles the single function to the Java code, while when importing the full library it imports the library as a object.