Java Standard Library: Complete Overview
The Java Standard Library (Java Standard Edition API) is a powerful and extensive set of classes and interfaces that provides developers with ready-made solutions for most common tasks. It is an integral part of the Java platform and covers everything from basic data types and working with collections to multithreading, input-output, and network communication. In this overview, we will look at the key packages and their capabilities.
Package java.lang — The Foundation of the Language
The java.lang package is imported automatically. It contains fundamental classes without which it is impossible to write any Java program.
- Object — the root class of the hierarchy. All classes inherit its methods (
equals(),hashCode(),toString()). - String, StringBuilder, StringBuffer — for working with immutable and mutable strings.
- Wrapper Types —
Integer,Double,Boolean, and others — allow using primitives in collections. - System — a utility class for working with the console (
System.out), system properties, and arrays (System.arraycopy()). - Math — provides mathematical constants and functions (
Math.sin(),Math.sqrt()).
// Example of using java.langpublic class LangExample { public static void main(String[] args) { String text = "Hello, Java!"; int length = text.length(); // 12 double root = Math.sqrt(25); // 5.0 System.out.println(text.toUpperCase()); // HELLO, JAVA! }}Package java.util — Collections and Utilities
This is one of the most popular packages. It includes the Collections Framework — a unified architecture for storing and processing data.
Collections
- List — an ordered list (allows duplicates). Implementations:
ArrayList,LinkedList. - Set — a set of unique elements. Implementations:
HashSet,TreeSet. - Map — a dictionary (key-value). Implementations:
HashMap,TreeMap. - Queue/Deque — queues for data processing (e.g.,
PriorityQueue).
import java.util.*;
public class CollectionsExample { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("Python"); list.add("Java"); // Duplicate is allowed
Set<Integer> set = new HashSet<>(); set.add(10); set.add(20); set.add(10); // Duplicate will be ignored
Map<String, Integer> map = new HashMap<>(); map.put("Alice", 30); map.put("Bob", 25);
System.out.println("List: " + list); System.out.println("Set: " + set); System.out.println("Map: " + map); }}Utilities
- Collections — static methods for sorting, searching, and synchronizing collections.
- Arrays — convenient work with arrays (
Arrays.sort(),Arrays.asList()). - Date, Calendar — for working with dates and times (deprecated in favor of
java.time). - Random — generating pseudo-random numbers.
Package java.io — Input-Output
This package provides classes for working with data streams: files, console, network connections. It is based on the concept of InputStream/OutputStream for bytes and Reader/Writer for characters.
- \
Also in library
Sending Email in C++: Libraries and Implementation
Working with Kafka in TypeScript: KafkaJS Library and Examples
Working with Kafka in Java: Libraries, Configuration, and Code Examples
Multer for JavaScript (Node.js): Complete Guide with Examples
Protocol Buffers for Java: Complete Guide with Examples