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
🌐
TutorialsPoint
tutorialspoint.com › static-import-the-math-class-methods-in-java
Static import the Math Class Methods in Java
The Math class is not required along with the method sqrt() as static import is used for the java.lang package. The number num and its square root is displayed. A code snippet which demonstrates this is as follows: double num = 36.0; System.out.println("The number is: " + num); System.out....
🌐
Reddit
reddit.com › r/learnjava › how come i didn't need to import java.lang.math for my code?
r/learnjava on Reddit: How come I didn't need to import java.lang.Math for my code?
January 24, 2015 -

I had this line of code:

int generator = 1 + (int) (Math.random() * 19);

http://puu.sh/sGVps/b318650d6b.png

The program I create works perfectly but i was wondering why I didn't need to import lang.math despite using random.

🌐
Quora
quora.com › How-do-I-import-a-math-class-in-Java
How do I import a math class in Java?
Answer (1 of 4): Math class is from java.lang package. So you dont have to import Math class. Also the methods and variables in Math class are static. So you can call them using class name.
🌐
Linux Hint
linuxhint.com › import-math-in-java
How to Import Math in Java? – Linux Hint
To import Math in Java, use “java.lang” package or import Math class using “java.lang.Math.*” It will access all the methods and variables of Math class.
🌐
Quora
quora.com › If-I-import-util-*-do-I-have-to-import-the-math-and-format-class-as-well
If I import util *, do I have to import the math and format class as well? - Quora
Answer (1 of 4): You should not import anything you do not use in your code. While it does not affect final output it just takes space and extra things in your source decreases readability of your code.
🌐
Coderanch
coderanch.com › t › 629237 › java › java-lang-Math-methods-import
Use java.lang.Math methods without import in IDE [Solved] (Beginning Java forum at Coderanch)
You could write your code using full class names including their package names. Like this: But the problem is... it looks ugly. Import statements are for us humans. Java compiler don't need them
🌐
FavTutor
favtutor.com › blogs › java-math-class
Math Class in Java & Methods (with Examples)
October 9, 2023 - This means that you can access the Math class without explicitly importing it. The Math class provides a wide range of mathematical functions and constants that are useful for various calculations.
🌐
Huda Tutorials
hudatutorials.com › java › lang › math
java.lang.Math Class in Java, Static Import
June 30, 2021 - The Math class exists in the java.lang package. That's why no need to import Math class in your programs . All the Math class methods are static .
Find elsewhere
🌐
Blogger
javahungry.blogspot.com › 2022 › 10 › import-math-class-java.html
How to import Math class in Java with examples | Java Hungry
The Math class is present in default package i.e. java.lang package. As a result, we do not need to explicitly import the Math class in Java program.
🌐
Quizlet
quizlet.com › science › computer science
Why does the Math class not need to be imported? | Quizlet
We don't have to import Math class because it is in the java.lang package which provides fundamental classes for the programming in Java language (e.g.
🌐
JavaBeat
javabeat.net › home › how to import math in java?
How to Import Math in Java?
March 13, 2024 - In Java, the Math class is not imported by default, however, the package to which it belongs (i.e., java.lang) is imported by default. Therefore, we can use/access this class without explicitly importing it.
🌐
Know Program
knowprogram.com › home › import math class in java
Import Math Class in Java - Know Program
June 27, 2023 - How to import math class in Java? The Math class in Java is available in java.lang package. Since java.lang package is the default package to every Java program, therefore there is no need to import the Math class explicitly in the program.
🌐
Sololearn
sololearn.com › en › Discuss › 1527906 › does-the-math-class-needs-to-be-imported-in-java-because-im-tring-to-use-the-mathpow-and-doesnt-work-and-if-so-how-do-i-do-it
Does the math class needs to be imported in java because im tring to use the math.pow and doesnt work.. and if so how do i do it | Sololearn: Learn to code for FREE!
I mean, you could import static java.lang.Math; 1st Oct 2018, 5:41 PM · LunarCoffee · 0 · thank you it worked but tring to go on and running the code tells me 'time limit exceeded' whats up with that? any idea? 1st Oct 2018, 4:19 PM · ThermalBlast22 · 0 · wierd its not long at all i think but its my first one so what do i know..
🌐
Code Underscored
codeunderscored.com › guide-to-importing-the-math-class-in-java
Guide to Importing the Math Class in Java | Code Underscored
To import Math in Java, you can use the “java.lang” package to access the methods or variables of the Java Math class using their class name. Another way of importing a Math class is to use the “java.lang.Math.*” import statement at ...
🌐
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 - Here’s when and why you should use the math library: When you need precise mathematical constants like math.pi or math.e.
🌐
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
🌐
Tutorialspoint
tutorialspoint.com › java › java_lang_math.htm
Java - Math Class
Following is the declaration for java.lang.Math class − ... static double E − This is the double value that is closer than any other to e, the base of the natural logarithms. static double PI − This is the double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter. This class inherits methods from the following classes − ... The following example shows the usage of some important ...