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
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › static-import-the-math-class-methods-in-java
Static import the Math Class Methods in Java
Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static. The Math class method sqrt() in the package java.lang is static imported. A program
🌐
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
Find elsewhere
🌐
Emory
mathcs.emory.edu › ~cheung › Courses › 170 › Syllabus › 04 › java-lib.html
Emory
import java.lang.Math in our program. Summary: importing methods in the Java library ·
🌐
Know Program
knowprogram.com › home › import math class in java
Import Math Class in Java - Know Program
June 27, 2023 - Learn more about how static import works, and the difference between normal import vs static import in Java:- Static import in Java. Statement to import Math class all static members:- import static java.lang.Math.*;
🌐
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 // incrementExact(), log10(), pow() import java.lang.*; public class NewClass { public static void main(String[] args) { // Use of incrementExact() method int f1 = 30, f2 = -56; f1 =Math.incrementExact(f1); System.out.println("Incremented value of f1 : "+f1); f2 =Math.incrementExact(f2); System.out.println("Incremented value of f2 : "+f2); System.out.println(""); // Use of log10() method double value = 10; double logValue = Math.log10(value); System.out.println("Log10 value of 10 : "+logValue); System.out.println(""); // Use of pow() method double b = 10, e = 2; double power = Math.pow(b,e); System.out.println("Use of pow() : "+power); } } Output :
🌐
Quora
quora.com › How-do-I-import-a-math-class-in-Java
How to import a math class in Java - Quora
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.
🌐
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.
🌐
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.
🌐
W3Schools
w3schoolsua.github.io › java › java_ref_math_en.html
Java Math Methods. Lessons for beginners. W3Schools in English
All Math Methods in Java. The Java Math class has many methods that allows you to perform mathematical tasks on numbers. All Math methods are static. Lessons for beginners. W3Schools in English
🌐
Huda Tutorials
hudatutorials.com › java › lang › math
java.lang.Math Class in Java, Static Import
June 30, 2021 - Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static. The Math class method sqrt() in the package java.lang is static import as stated in the following example.
🌐
Emory
cs.emory.edu › ~cheung › Courses › 170 › Syllabus › 04 › java-lib.html
Importing methods in the Java library
import java.lang.Math in our program. Summary: importing methods in the Java library ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-class
Java Math Class - GeeksforGeeks
July 23, 2025 - Java.lang.Math Class methods help to perform numeric operations like square, square root, cube, cube root, exponential and trigonometric operations.
🌐
DataCamp
datacamp.com › doc › java › java-math
Java Math
Java keywordsIntroduction To JavaJava File HandlingJava Language BasicsJava ArraysJava Object-Oriented Programming ... The Math class in Java is part of the java.lang package and provides a collection of methods for performing basic numeric operations such as exponential, logarithm, square root, and trigonometric calculations.
🌐
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 module provides functions for square roots, trigonometry, logarithms, constants like π (pi) and e, and much more. ... Once imported, you can access its functions using the dot notation.