Popular Google Pages:

◕ Bengali Story writing competition. More..

This article is regarding **Importing the Math Class Methods in Java.**

Last updated on: 31st March 2017.

◕ Importing the Math Class Methods

Let have two examples statement first:

■ First Example:

**valueOfPI = Math.PI;**

In this case we want to find the value of **π**.

For this we called the static method **PI** from the **Math Class.**

■ Second Example:

Again if we call another static method then we have to write like:

squreValue = Math.sqrt(anyArgument);

Here we find the squre root value of an argument.

■ In the above two examples we find that if we call any static method from the **Math Class**
we have to write the class name ( i.e Math. ) again and again.

This increases the length or our program.

We can avoid this by **importing the Math Class.**

We can import the **Math Class** in two ways.

■ 1st Way - Importing the all static method from Math Class.

We have to write this line in the beginning of our program.

**import static java.lang.Math.*;**

This line means we are importing **all static methods** from the **Math Class.**

Now we can write the above two examples as:

**valueOfPI = PI;**

squreValue = sqrt(anyArgument);

■ 2nd Way - Importing a single static method from Math Class.

We have to write this line in the beginning of our program.

**import static java.lang.Math.PI;**

This line means we are importing **only the PI method** from the **Math Class.**

Now we can write the above example as:

**valueOfPI = PI;**

Related Java articles:

■ What is Java? Where we can apply Java?

■ Why Java is a Machine Independent Program? What is Machine Independent Program?

■ Root Directory of Java

■ How to Compile and run a Java Program?

■ What is .class file in Java?

■ What is variable in a program?

■ What is identifier in Java?

■ Integer data types in Java?

■ What is Primitive Types in Java?

■ How to declare constant variables in Java?

■ Why should we declare the initial value of a variable in Java?

■ Use of Underscores to write an integer in Java

Top of the page