10.4. The Math Class

The final class Math defines a set of static methods to support common mathematical functions, including functions for rounding numbers, performing trigonometry, generating pseudo random numbers, finding maximum and minimum of two numbers, calculating logarithms and exponentiation. The Math class cannot be instantiated. Only the class name Math can be used to invoke the static methods.

The final class Math provides constants to represent the value of e, the base of the natural logarithms, and the value π (pi), the ratio of the circumference of a circle to its diameter:

Math.E
Math.PI

Miscellaneous Rounding Functions

static int    abs(int i)
static long   abs(long l)
static float  abs(float f)
static double abs(double d)

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.