Math class Methods Java

Math class Methods Java

One of the important packages of Java is java.util. The classes of this package are known as utility classes. Literal meaning of utility is a service we use everyday. For example, Water, Power supply and Sewerage department etc are known as utility services. Similarly some classes exist which we use generally in every Program; they are known as utility classes – Date, Calendar, Math, Random etc.

Here, we discuss java.lang.Math class methods frequently used and rarely used separately.

All methods of Math class static methods so that you can call them with class name directly without creating object.

These methods used for simple arithmetic operations are self-explanatory and exist in many languages.

See the signature of Math class as defined in java.lang package.

public final class Math extends Object

Being final, Math class cannot be extended.

The Math class includes only two static final constants as defined here under.

public static final double E = 2.7182818284590452354; (Natural logarithm base)

public static final double PI = 3.14159265358979323846; (Circle circumference to diameter)

Following example uses Math class Methods frequently used.

ssOutput screenshot of Math class methods frequently used.

Following example uses Math class Methods rarely used.

ssOutput screenshot of Math class methods rarely used.

Other java.util package service classes

1. class Date
2. class Calendar
3. class GregorianCalendar
4. class Random
5. Timer and TimerTask
6. classes Observer and Observable
7. class StringTokenizer

Leave a Reply

Your email address will not be published. Required fields are marked *