The number π is a mathematical constant, the ratio of a circle’s circumference to its diameter, commonly approximated as 3.14159. It has been represented by the Greek letter “π” since the mid-18th century, though it is also sometimes spelled out as “pi” (/paɪ/).

^{From: Wikipedia}

The code snippet below show you how to obtain the PI value in Java. We use the `Math.PI`

static field to get the value of PI.

```
package org.kodejava.example.math;
public class GetPiExample {
public static void main(String[] args) {
// The PI value represented by Math.PI
System.out.println("PI = " + Math.PI);
// Using the Math.PI to calculate area of a circle.
double radius = 8;
double circleArea = Math.PI * Math.pow(radius, 2);
System.out.println("Circle Area = " + circleArea);
}
}
```

Here is the program output:

PI = 3.141592653589793 Circle Area = 201.06192982974676

### Wayan Saryada

Founder at Kode Java Org

I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳

#### Latest posts by Wayan Saryada (see all)

- How do I clear the current command line in terminal? - February 14, 2019
- How do I generate random alphanumeric strings? - February 7, 2019
- Why do I get ArrayIndexOutOfBoundsException in Java? - January 29, 2019

Nice article. Thanks for sharing such a informative article.

Nice, very interesting. If you want to know more about the value of pi, visit http://www.proofpi.com