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
🌐
W3Schools Blog
w3schools.blog › home › import math java
import math java - W3schools
January 23, 2022 - import java.lang.Math.*; Example class MathJava { public static void main(String[] args) { // Declaring the variables int num1 = -2; float num2 = .8f; // Printing the values System.out.println("Initial value of int : "+num1); System.out.println("Initial value of int : "+num2); // Use of .abs() ...
🌐
W3Schools
w3schools.com › java › java_math.asp
Java Math
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
W3Schools
w3schools.com › java › java_ref_math.asp
Java Math Reference
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
Quora
quora.com › How-do-I-import-a-math-class-in-Java
How do I import a math class in Java?
java.math.BigInteger and BigDecimal: require explicit import (they are in java.math). Use for arbitrary-precision integer and decimal arithmetic. ... Then call sqrt(9) or PI directly.
🌐
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.

🌐
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.
🌐
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
🌐
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.
🌐
JavaBeat
javabeat.net › home › how to import math in java?
How to Import Math in Java?
March 13, 2024 - Math is a predefined utility class in Java that belongs to Java’s default package named “java.lang”. It offers several methods that can be used with or without importing the Math class into a Java Program.
🌐
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)
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums · this forum made possible by our volunteer staff, including ... ... I am able to use a Math method without importing the java.lang.Math.
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
Code Underscored
codeunderscored.com › guide-to-importing-the-math-class-in-java
Guide to Importing the Math Class in Java | Code Underscored
In Java, the Math class belongs to the “java.lang” package; hence you can use the “Math” class without importing it. This package allows using the associated classes implicitly.