Java standard library overview: the core packages and what they're for

The Java standard library (the Java Class Library, or “the JDK APIs”) is the set of classes that ships with every JDK. Before reaching for a third-party dependency, it’s worth knowing what’s already there: collections, dates and times, file I/O, networking, an HTTP client and concurrency utilities are all built in.
Since Java 9 the library is split into modules. The packages below all live in the java.base module, except java.net.http, which is in java.net.http. Both are available by default in a normal JDK.
java.lang
Section titled “java.lang”Imported automatically into every source file. The classes you use without thinking about it:
Object: the root of the class hierarchy (equals,hashCode,toString).String: an immutable sequence of characters.StringBuilder: a mutable buffer for building strings in a loop.StringBufferdoes the same but synchronizes every method, so preferStringBuilderunless several threads share one buffer.Math: static methods such asMath.max,Math.sqrtandMath.floorMod.System: standard streams (System.out,System.err,System.in), environment variables andSystem.nanoTime()for timing.- Wrapper types (
Integer,Long,Double, …) andThread.
java.util
Section titled “java.util”Collections and general utilities:
- Lists, sets and maps:
ArrayList,LinkedList,HashSet,TreeSet,HashMap,TreeMap. TheTree*variants keep their elements sorted. CollectionsandArrays: static helpers for sorting, searching and wrapping collections.Optional,Random,Objects,Scanner.java.util.stream: the Streams API (map,filter,collect).java.util.concurrent: thread pools (ExecutorService),ConcurrentHashMap,CompletableFuture.
java.util.Date, Calendar and TimeZone are still here, but they are legacy. For new code use java.time.
java.time
Section titled “java.time”Added in Java 8 to replace Date and Calendar. The types are immutable and say what they mean: LocalDate (a date with no time zone), LocalDateTime, ZonedDateTime, Instant (a point on the UTC timeline), Duration and Period. DateTimeFormatter handles parsing and formatting.
java.io
Section titled “java.io”The original stream-based I/O API:
InputStream/OutputStreamfor bytes andReader/Writerfor characters.BufferedReader,BufferedWriter,FileReader,FileWriterand friends that wrap them.File: a file or directory path. It still works, butjava.nio.file.Pathis the better choice for new code.
Sockets in java.net also expose their data as java.io streams.
java.nio and java.nio.file
Section titled “java.nio and java.nio.file”NIO stands for “New I/O”. The java.nio package itself holds the buffer classes (ByteBuffer, CharBuffer, IntBuffer and so on). Related packages:
java.nio.channels: channels, which read and write buffers, plusSelectorfor non-blocking socket I/O.java.nio.file:Path,PathsandFiles. This is the modern file API, with one-liners likeFiles.readString,Files.linesandFiles.walk, and exceptions that say why an operation failed (File.delete()only returnsfalse).
java.net and java.net.http
Section titled “java.net and java.net.http”java.net has URI, URL, Socket, ServerSocket and DatagramSocket for TCP and UDP. For HTTP, use java.net.http.HttpClient (Java 11+) rather than the older HttpURLConnection. It supports HTTP/2 and has both synchronous send and asynchronous sendAsync.
A small example
Section titled “A small example”You import individual classes (or a whole package with *), not the library as a whole. This program counts the words in a text file using java.nio.file, java.util and java.time:
import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;import java.time.LocalDate;import java.util.List;import java.util.Map;import java.util.TreeMap;
public class WordCount { public static void main(String[] args) throws IOException { Path file = Path.of(args.length > 0 ? args[0] : "notes.txt"); List<String> lines = Files.readAllLines(file);
Map<String, Integer> counts = new TreeMap<>(); for (String line : lines) { for (String word : line.toLowerCase().split("\\W+")) { if (!word.isEmpty()) { counts.merge(word, 1, Integer::sum); } } }
System.out.println("Word counts for " + file + " on " + LocalDate.now()); counts.forEach((word, n) -> System.out.println(word + ": " + n)); }}On Java 11 or later you can run a single source file directly, without compiling it first:
java WordCount.java notes.txtTreeMap keeps the words in alphabetical order. Swap it for HashMap if order doesn’t matter.
Further reading
Section titled “Further reading”- Java SE API documentation, organized by module
- The
java.timepackage java.net.http.HttpClient
© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)