[MUSIC] Welcome to the next lesson in our module on basic Java features where you will learn about Java's Math class, which contains a large collection of common mathematical functions. After completing this lesson, you will understand the purpose of the Math class. And be familiar with many of its methods. You will also know how to call a method in this and use the result in larger mathematical expression. In addition, you'll recognize key predefined constants in the math class. Finally, you will learn how to apply type casting in conjunction with certain math methods. When it is required by the Java language. [MUSIC] In this lesson, we are going to learn about Java's Math class and its available functions, and how to use them. Recall from your high school trig class that the tangent of an angle was computed by dividing the sine of the angle by the cosine of the angle. Now, if we were to do similar computation in a Java program, we would want to save the results of the division operation in a variable. But for now, let's focus on the operands of the division operation. When we see sin(x) we understand that there exist some function sine that takes a parameter x, which represents the angle we're interested, and the function called sine of x will return the value of the sine of that angle. Similarly, cosine of x will return to us the value of the cosine of the angle x. It is functions like these that we want to explore in this lesson. The Java language provides many useful predefined functions which are grouped together in collections called classes. In particular, there is the math class that provides many of the standard math functions that we may want to use. In Java terminology, these functions are referred to as methods. And for the Math class, all these methods will return values back to us that we can then use as we wish. To use or call these methods, we need to specify the class name, which is Math with a capital m, followed by a dot, which is followed by the name of the method. The parameters that we want the method to operate on are specified in parentheses, just like in mathematics. The Math class and it's methods are available to all Java programs. You do not need to do anything special in your code to indicate that you want to use them. Most of the Math methods expect you to supply parameters on which you want them to operate. Again, these go inside the parentheses that follow the method name. If there are multiple parameters, you separate them with commas. You must always have the parentheses for the list of parameters, even if the method does not take any parameters. In that case the parenthesis are empty. In a key feature of all the methods of the Math class is that they return a numeric value that you can use in some expression. Here are several examples. Calling Math.sqrt will compute the square root of the primer. Calling Math.abs will compute, you guessed it, the absolute value. And calling Math.min will determine which of two values is the minimum, or smaller value. Here are some of the more popular Math methods. We see we can compute the absolute value. We can round a value to the nearest whole number. We can round a number up or down. We can compute the logarithm of number. And we can find the larger or smaller of two values. We can also compute the result of raising one value to the power of another. We can compute the square root and the standard trig functions, sine, cosine, and tangent. Note that the trig functions expect the angle to be measured in radians rather than degrees. But luckily, there are methods that allow us to convert between degrees and radians. And there is a method that will return us a random floating play value in the range from zero to one. Note that this is an example of a method call with no parameters. The Math class has many more methods than the ones presented here. Perform an appropriate web search for a complete list. The Math class also has two predefined constants, E, which holds Euler's number that is often used in calculating compound interest and other interests, and the constant pi that we use in geometry and trigonometry. To access these constants you must use the dot notation with the class name Math. Before we end this lesson, let's take a closer look at the methods that round floating point values. The round method will of course round a floating point value to the nearest whole number. The interesting thing about this method is that if the parameter is type double, then the result is a type long. Now, the floor method returns the largest whole number that is smaller than the parameter, ie, it always rounds down, while the ceil method, short for ceiling, returns the smallest whole number larger than the parameter, ie, it always rounds up. These two functions, when given a parameter of type double, will return a value of type double. So these three methods always return whole numbers which we may likely want to assign to variables of type int. But we learned earlier that Java's type compatibility rules will not allow us to directly assign values of type double or long to a variable of type int. Rather, such values must be cast prior to being assigned to an integer variable. [MUSIC] This lesson presented an overview of Java's Math class, which contains a large collection of common mathematical functions. Now that you have completed this lesson, you should understand the role of the Math class and be familiar with many of its methods. You should also know how to call a method of the Math class and how to use the result. In addition, you should recognize key constants provided in the Math class. Finally, you should have learned how to apply typecasting in conjunction with certain Math methods when required by the Java language. [MUSIC]