zuai-logo

Glossary

M

Math class

Criticality: 3

A built-in Java class that provides a collection of static methods for performing common mathematical operations.

Example:

To calculate the square root of 16, you would use Math.sqrt(16), demonstrating how the Math class provides ready-to-use functions.

Math.abs()

Criticality: 3

A static method in the Math class that returns the absolute value of a number, meaning its non-negative distance from zero.

Example:

If a game character moves 5 units left (-5) or 5 units right (5), Math.abs(-5) and Math.abs(5) both return 5, showing the magnitude of movement regardless of direction, thanks to Math.abs().

Math.pow()

Criticality: 3

A static method in the Math class that returns the value of the first argument raised to the power of the second argument.

Example:

To calculate the area of a square with side length s, you might use Math.pow(s, 2) to get s squared, illustrating how Math.pow() handles exponents.

Math.random()

Criticality: 3

A static method in the Math class that returns a pseudo-random double value greater than or equal to 0.0 and less than 1.0.

Example:

To simulate a coin flip, you could check if Math.random() < 0.5 for 'heads', demonstrating how Math.random() provides a basis for random events.

Math.sqrt()

Criticality: 3

A static method in the Math class that returns the positive square root of a double value.

Example:

Finding the length of the hypotenuse in a right triangle with legs of 3 and 4 would involve Math.sqrt(Math.pow(3, 2) + Math.pow(4, 2)), where Math.sqrt() calculates the final root.

R

Random number generation in a range

Criticality: 3

The process of using `Math.random()` to produce a random integer within a specified inclusive lower bound and exclusive upper bound.

Example:

To simulate rolling a standard six-sided die, you would use (int)(Math.random() * 6) + 1, which is an example of random number generation in a range from 1 to 6.

s

static

Criticality: 3

A keyword in Java indicating that a method or variable belongs to the class itself, rather than to any specific object of that class.

Example:

Because Math.abs() is a static method, you call it directly on the Math class (e.g., Math.abs(-10)) without needing to create a new Math() object first.