## Class Math in Java

Math class contains methods for performing basic numeric operations viz mathematical operation. The Math class is in java.lang package hence we do not require to import the same package.

The Math class contains constants for the mathematical values pi and e. The class also defines methods that compute various mathematical functions, such as trigonometric and exponential functions. All of these constants and methods are static. In other words, it is not necessary to create an instance of the Math class in order to use its constants and methods. In fact, the Math class does not define any public constructors, so it cannot be instantiated.

Math.random() never produces zero or one. It always is between 0 and 1. Math class defines constants for the mathematical values of e and PI. Math class also defines several static methods for floating-point trigonometry, exponential and other operations.

### The class structure of Math is given below:

```
public final class java.lang.Math extends java.lang.Object{
//member elements
public final static double E;//E =2.7182818284590452354(double value of E)
public final static double PI;//PI=3.14159265358979323846 (double value of PI)
//methods
public static double abs(double a);//returns the absolute value of the argument
public static native double acos(double a);//returns the acos or arc cos value of the argument passed
public static native double asin(double a);//returns the asin or arc sin value of the argument passed
public static native double atan(double a);//returns the atan or arc tan value of the argument passed
public static native double atan2(double a,double b);//returns theta after converting rectangular
//co-ordinates(a,b) to polar Double (r,theta).
public static native double ceil(double a);//returns the smallest integer less than or equal to the argument.
//This is also called rounding up.
public static native double cos(double a);//returns the cos value of the argument passed
public static native double exp(double a);//returns the base of natural log(e) to the power argument
public static int round(double a);//returns the closed int or long
public static native double floor(double a);//returns the largest integer that is less than or equal to the argument.
//This is also called rounding down.
public static native double IEEEremainder(double a,double b);
public static double toDegree(double a);//returns the degree from the specified argument.
public static double toRadian(double a);//returns the radian from the specified argument.
public static native double log(double a);//returns the natural log of the argument
public static double max(double a,double b);//returns the higher of the two argument passed
public static synchronized double random();//returns a generated random number
public static native double rint(double a);//returns the truncated value of the argument.
public static native double sin(double a);//returns the sin value of the argument passed
public static native double sqrt(double a);//returns the square root of the argument
public static native double tan(double a);//returns the tan value of the argument passed
public static native double pow(double a,double b);//returns the argument1 to the power argument2 here
//a to the power b
public static double min(double a,double b);//returns the smaller of the two argument passed
public static int abs(int a);//returns the absolute value of the argument
public static int max(int a,int b);//returns the higher of the two argument passed
public static int min(int a,int b);//returns the smaller of the two argument passed
public static int round(float a);//returns the closed int or long
public static long abs(long a);//returns the absolute value of the argument
public static long max(long a,long b);//returns the higher of the two argument passed
public static long min(long a,long b);//returns the smaller of the two argument passed
public static long round(double a);
public static float abs(float a);//returns the absolute value of the argument
public static float max(float a,float b);//returns the higher of the two argument passed
public static float min(float a,float b);//returns the smaller of the two argument passed
}
```

The details of the class structure are given as follows:

`public static final double E;`

public static final double E describes the value of this constant is e, the base for natural logarithms.E = 2.7182818284590452354

`public static final double PI;`

public static final double PI describes the value for this constant is pi. PI = 3.14159265358979323846

`public static int abs(int a);`

public static int abs(int a) method returns the absolute value of its argument. If the argument is Integer.MIN_VALUE, the method actually returns Integer.MIN_VALUE because of the true absolute value of Integer.MIN_VALUE is one greater than the largest positive value that can be represented by an int.

This method returns the absolute value of its argument.

**Parameter**

**a** – An int value.

`public static long abs(long a);`

public static long abs(long a) method returns the absolute value of its argument.If the argument is Long.MIN_VALUE, the method actually returns Long.MIN_VALUE because the true absolute value of Long.MIN_VALUE is one greater than the largest positive value represented by a long.

This method returns the absolute value of its argument.

**Parameter**

**a** – A long value.

`public static float abs(float a);`

public static float abs(float a) method returns the absolute value of its argument. If the argument to this method is negative or positive zero, the method should return positive zero. If the argument is positive or negative infinity, the method returns positive infinity. If the argument is NaN, the method returns NaN.

This method returns the absolute value of its argument

**Parameter**

**a** – A float value.

`public static double abs(double a);`

public static double abs(double a) method returns the absolute value of its argument. If the argument to this method is negative or positive zero, the method should return positive zero. If the argument is positive or negative infinity, the method returns positive infinity. If the argument is NaN, the method returns NaN.

This method returns the absolute value of its argument.

**Parameter**

**a** – A double value.

`public static native double acos(double a);`

public static native double acos(double a) method returns the arc cosine of the given value. If the value is NaN or its absolute value is greater than 1.0, the method returns NaN.

This method returns the arc cosine measured in radians; the result is greater than or equal to 0.0 and less than or equal to pi.

I’m not that much of a online reader to be honest but your

blogs really nice, keep it up! I’ll go ahead and bookmark your website to come back later on. Many thanks