Java Libraries
The libraries that today's Java developers actually use — frameworks, HTTP, JSON, database, testing, security.
The dominant Java framework for building production applications. Convention over configuration, autoconfigured starters, embedded server.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
Kubernetes-native Java framework with fast startup and low memory. Compiles to native via GraalVM.
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-rest</artifactId> </dependency>
Compile-time DI framework — no runtime reflection. Fast startup, low memory.
<dependency> <groupId>io.micronaut</groupId> <artifactId>micronaut-http-server-netty</artifactId> </dependency>
Square's HTTP client. Connection pooling, transparent GZIP, response caching, HTTP/2.
OkHttpClient client = new OkHttpClient();
Request req = new Request.Builder()
.url("https://api.example.com")
.build();
try (Response res = client.newCall(req).execute()) {
System.out.println(res.body().string());
}Type-safe HTTP client built on OkHttp. Define an interface, Retrofit generates the implementation.
interface UserApi {
@GET("users/{id}")
Call<User> getUser(@Path("id") String id);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(JacksonConverterFactory.create())
.build();
UserApi api = retrofit.create(UserApi.class);The standard Java JSON library. Fast, configurable, supports streaming and tree-model APIs.
ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(user); User back = mapper.readValue(json, User.class); JsonNode node = mapper.readTree(json);
Google's JSON library. Simpler API than Jackson but slower. Great for quick scripts.
Gson gson = new Gson(); String json = gson.toJson(user); User back = gson.fromJson(json, User.class);
The original Java ORM. Implements JPA. Mature but heavyweight; LAZY loading footguns.
@Entity
public class User {
@Id @GeneratedValue Long id;
String email;
}
EntityManager em = ...;
User u = em.find(User.class, 42L);Type-safe SQL DSL. Generate Java classes from your schema, then write SQL with the IDE's full power.
Result<Record> result = create
.select()
.from(USERS)
.where(USERS.ACTIVE.eq(true))
.orderBy(USERS.NAME)
.fetch();The fastest JDBC connection pool. Default in Spring Boot.
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:postgresql://localhost/mydb");
config.setMaximumPoolSize(20);
HikariDataSource ds = new HikariDataSource(config);Database migrations as numbered SQL files. The de facto standard.
// db/migration/V1__create_users.sql CREATE TABLE users ( id BIGSERIAL PRIMARY KEY, email TEXT UNIQUE NOT NULL ); // runs automatically with spring-boot-starter-flyway
The standard Java testing framework. Annotations, parameterized tests, dynamic tests, extensions.
@Test
void shouldAddNumbers() {
assertEquals(5, calc.add(2, 3));
}
@ParameterizedTest
@ValueSource(ints = {1, 2, 3})
void positive(int n) { assertTrue(n > 0); }Fluent assertions that read like English. Massively better error messages than JUnit's built-in assertions.
assertThat(users)
.hasSize(3)
.extracting(User::name)
.containsExactly("Ada", "Grace", "Linus");The standard mocking library. Stub, verify, spy.
UserRepo repo = mock(UserRepo.class); when(repo.findById(42L)).thenReturn(Optional.of(user)); UserService svc = new UserService(repo); svc.greet(42L); verify(repo).findById(42L);
Spin up real Docker containers from your tests. Postgres, Kafka, Redis, anything with an image.
@Container
PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16");
@Test
void integrationTest() {
String url = postgres.getJdbcUrl();
// run real queries against a real Postgres
}XML-based build tool. Everyone knows it; everyone has a love-hate relationship with it.
<project>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>Groovy / Kotlin DSL build tool. More flexible than Maven, faster incremental builds.
// build.gradle.kts
plugins {
java
id("org.springframework.boot") version "3.3.0"
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}SLF4J is the logging facade everyone codes against. Logback is the most common implementation.
private static final Logger log = LoggerFactory.getLogger(MyClass.class);
log.info("Processing user {}", userId);
log.warn("Slow query: {} ms", elapsed);
log.error("Failed", exception);Apache logging framework. Async logging, JSON layouts. Use the latest version (post-Log4Shell).
private static final Logger log = LogManager.getLogger();
log.info("Hello, {}", name);Reactive Streams for Java. Backbone of Spring WebFlux. Mono / Flux types.
Flux.fromIterable(userIds)
.flatMap(userRepo::findById)
.filter(u -> u.isActive())
.map(User::email)
.collectList()
.subscribe(emails -> log.info("Found {}", emails));The original ReactiveX implementation for Java. Less common in new server code (Reactor wins) but huge on Android.
Observable.fromIterable(items)
.filter(i -> i.value > 0)
.map(Item::name)
.subscribe(System.out::println);Annotation processor that generates getters, setters, equals, builders at compile time. Reduces boilerplate.
@Data
@Builder
public class User {
private Long id;
private String email;
// getters, setters, equals, hashCode, toString, builder — generated
}
User u = User.builder().id(1L).email("a@b.c").build();Google's core libraries. Caches, immutable collections, string/file utilities, EventBus.
Cache<String, User> cache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(Duration.ofMinutes(10))
.build();
ImmutableList<String> list = ImmutableList.of("a", "b", "c");Grab-bag of mature utility libraries. commons-lang3, commons-io, commons-text, commons-csv, etc.
// commons-lang3
StringUtils.isBlank(" "); // true
StringUtils.capitalize("hello"); // "Hello"
// commons-io
String content = FileUtils.readFileToString(file, UTF_8);Auth and authorization for Spring. OAuth 2, JWT, method-level security, CSRF, CORS.
@Bean
SecurityFilterChain chain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(a -> a
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated())
.oauth2ResourceServer(oauth -> oauth.jwt(Customizer.withDefaults()))
.build();
}Password hashing with built-in salt and work factor. Never store plain passwords.
BCryptPasswordEncoder enc = new BCryptPasswordEncoder(12);
String hash = enc.encode("hunter2");
boolean ok = enc.matches("hunter2", hash);JWT and JOSE (signing, encryption) libraries. Nimbus is the more popular of the two.
JWSSigner signer = new MACSigner(secret);
SignedJWT jwt = new SignedJWT(
new JWSHeader(JWSAlgorithm.HS256),
new JWTClaimsSet.Builder()
.subject("alice")
.expirationTime(new Date(System.currentTimeMillis() + 60_000))
.build());
jwt.sign(signer);
String serialized = jwt.serialize();