Java's standard library has grown across three decades, and its strong backward-compatibility guarantee means flawed early designs are rarely removed, only superseded — java.time (added in Java 8, based on the well-regarded Joda-Time library) is the modern, immutable, thread-safe replacement for the old, mutable, confusingly-designed java.util.Date and Calendar classes, which still exist purely for legacy code. java.util.Objects provides small null-safe utility methods (equals, hashCode, requireNonNull) that remove a surprising amount of repetitive boilerplate from everyday code.
java.time: the modern date/time API (Java 8+)
Unlike the old Date class, every java.time type is immutable and thread-safe — a method like plusDays() returns a new instance rather than mutating the original, exactly like Java's own String.
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
LocalDate today = LocalDate.now();
LocalDate nextWeek = today.plusDays(7); // returns a NEW LocalDate — today is unchanged
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd MMM yyyy");
System.out.println(today.format(fmt));
LocalDateTime now = LocalDateTime.now(); // date AND time togetherjava.util.Objects: small null-safe utilities
These small methods remove a surprising amount of boilerplate — requireNonNull throws immediately with a clear message rather than letting a null silently propagate to fail confusingly somewhere else later.
import java.util.Objects;
public Person(String name) {
this.name = Objects.requireNonNull(name, "name must not be null");
}
// null-safe equals: doesn't throw if either argument is null
boolean same = Objects.equals(a, b);
// correct hashCode combining multiple fields
public int hashCode() {
return Objects.hash(name, age, email);
}Math: static utility methods, no instantiation needed
Every method on java.lang.Math is static — there's no Math object to create, and the class itself can never be instantiated.
double root = Math.sqrt(16); // 4.0
int max = Math.max(3, 7); // 7
double rounded = Math.round(3.6); // 4
double random = Math.random(); // [0.0, 1.0)