The Math class in Java provides fundamental mathematical functions and constants. As part of the java.lang package, it requires no explicit import.
Key Functionalities:
- Mathematical constants like PI and E
- Basic operations: square roots, exponents, absolute values
- Trigonometric and logarithmic functions
Example Usage:
double circleRadius = 7.5;
double circleArea = Math.PI * Math.pow(circleRadius, 2);
System.out.println("Area: " + circleArea);
Important Considerations:
- Floating-point precision limitations
- Random number generation ranges
- Paramter and return types (primarily double)
System Operations in Java
The System class offers system-level operations and properties.
Core Features:
- Standard I/O streams management
- System properties access
- Memory operations and time measurement
- Efficient array copying
Practical Examples:
// Get current timestamp
long timestamp = System.currentTimeMillis();
// Copy array elements
int[] source = {10, 20, 30};
int[] destination = new int[3];
System.arraycopy(source, 0, destination, 0, 3);
Runtime Environment Management
The Runtime class provides control over the JVM environment.
Primary Capabilities:
- Memory monitoring and management
- External process execution
- System information retrieval
Implementation Example:
Runtime jvm = Runtime.getRuntime();
long freeMemory = jvm.freeMemory();
Process editor = jvm.exec("gedit");
Object Class Fundamentals
As Java's root class, Object provides essential methods inherited by all classes.
Key Methods:
- equals() - Object comparision
- hashCode() - Hash code generation
- toString() - String representation
- clone() - Object duplication
Objects Utility Class
Introduced in Java 7, Objects provides null-safe operations.
Common Methods:
- isNull() - Null check
- equals() - Safe comparison
- hash() - Hash code calculation
- requireNonNull() - Null validation
Usage Example:
String test = null;
if (Objects.isNull(test)) {
System.out.println("Variable is null");
}