Learn Java
import com.learnjava.packagesstandardlibrary.BuiltinClasses;

Useful Built-in Classes (Math, Arrays, Objects) in Java

@Concept

Beyond the core language, Java's standard library ships several extremely commonly-used utility classes worth knowing well: Math offers static methods for anything beyond basic arithmetic — sqrt, pow, abs, max, min, and many more — Arrays offers static utility methods for working with plain arrays — sort, a proper toString for readable printing, equals for content comparison, and fill for filling every slot with one value — and Objects offers null-safe utility methods, most usefully equals(a, b), which safely compares two references even if either one might be null.

All of these are static utility classes, meaning every method is called directly through the class name with no object to create first. Reaching for one of these well-tested, already-optimized methods is almost always a better choice than hand-rolling the equivalent logic from scratch.

@HowItWorks
1

Math

Static methods for anything beyond basic arithmetic: sqrt, pow, abs, max, min, and many more, all callable with no object to create.

2

Arrays.sort() and Arrays.toString()

Sort a plain array in place, and produce a properly formatted, readable String for printing it.

3

Arrays.equals()

Compares two arrays' contents element by element, unlike ==, which would only compare their references.

4

Objects.equals(a, b)

Null-safely compares two references, returning true if both are null, avoiding a NullPointerException a direct a.equals(b) could throw if a were null.

5

All static utility classes

Every method here is called through the class name directly, with no object of Math, Arrays, or Objects ever needing to be created.

@Example
import java.util.Arrays;
import java.util.Objects;
 
public class BuiltinClassesDemo {
public static void main(String[] args) {
int[] numbers = {3, 1, 2};
Arrays.sort(numbers);
System.out.println("Sorted: " + Arrays.toString(numbers));
 
String a = null;
System.out.println("Null-safe equals: " + Objects.equals(a, "hi"));
}
}
Output
Sorted: [1, 2, 3]
Null-safe equals: false
1Arrays.sort(numbers) reorders the array in place, from [3, 1, 2] to [1, 2, 3].
2Arrays.toString(numbers) produces a properly formatted, readable representation of that sorted array.
3Objects.equals(a, "hi") compares a, which is null, against "hi" safely, without ever risking calling a method directly on the null reference itself.
4Both println calls run once each, showing the sorted array and the safe comparison's result.
@UseCases
Sorting and printing a plain array readably without hand-writing a loop
Comparing two references safely when either one might legitimately be null
Computing a square root, power, or absolute value without any custom math code
Reaching for a well-tested standard library method instead of a hand-rolled equivalent

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Java yourself — building beats watching.