Skip to content

The Math Class

Estimated time to read: 1 minute

Overview

The Math class provides useful functions for operations beyond those provided by the basic operators such as + and -.

Math contains static methods, this means that you do not need to instantiate it. To use Math methods, use the class name followed by the method that needs to be accessed.

Documentation

Oracle Documentation - Java 8 - java.lang.Math.* Note that java.lang.Math is a class, and because it is part of the java.lang package, is implicitly available without importing. We only use import with java.lang.Math if we are using static imports.

On the other hand, java.math is a package, and home to the BigDecimal class, which is what we should be using for currency calculations. IEEE floating point is not an acceptable implementation for monetary calculation.