Java

223 posts in this section

SecurityFilterChain Bean: The Modern Configuration API

The Modern Configuration Model Spring Security 6.x dropped WebSecurityConfigurerAdapter. The new model uses a SecurityFilterChain @Bean directly. This is not just a syntax change — it’s a fundamentally cleaner design: Old approach New approach Extend WebSecurityConfigurerAdapter @Bean SecurityFilterChain method Override configure(HttpSecurity) Accept HttpSecurity parameter Chain with .and() Lambda DSL — each concern is a separate block One class per application Multiple beans, one per URL namespace Implicit global AuthenticationManager Explicit AuthenticationManager bean // OLD — don't do this @Configuration public class OldSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.

Continue reading »

Seeking to Specific Offsets: Replay, Recovery, and Time-Based Seeking

Why Seek Instead of Reset? Offset management (auto-commit vs manual acknowledgment) controls when offsets advance during normal processing. Seeking is different: it lets you reposition the consumer to any offset — past or future — programmatically, without touching the committed offset in __consumer_offsets. Common scenarios: Replay from the beginning — reprocess all historical events after a bug fix Resume from a known-good offset — skip a poison pill that’s blocking the consumer Time-based replay — reprocess everything since yesterday 09:00 Startup positioning — always start from the end, ignoring backlog on first launch How Kafka Seeking Works flowchart LR subgraph Broker["

Continue reading »

Sending Messages with Keys, Headers, and Custom Partitioning

Why Partitioning Strategy Matters How you route messages to partitions determines: Ordering: only messages in the same partition are ordered relative to each other Parallelism: how evenly work is distributed across consumers Hot spots: if one key generates 90% of traffic, one partition (and one consumer) gets 90% of the load flowchart TD subgraph Routing["Message Routing Decision"] Msg["Message"] HasKey{Has key?} HasPartition{Explicit partition?} KeyHash["hash(key) % numPartitions\n→ deterministic, same partition always"] RoundRobin["Sticky partitioning\n(batch to same partition,\nthen round-robin)"

Continue reading »

Sequenced Collections (JEP 431): A Unified API for Ordered Collections

The 30-Year Gap in the Collections API Java’s Collections Framework has a fundamental inconsistency: there is no uniform way to access the first or last element of an ordered collection. Before Java 21: // List — index-based var list = List.of("a", "b", "c"); String first = list.get(0); // first element String last = list.get(list.size() - 1); // last element — verbose, error-prone // Deque — special methods Deque<String> deque = new ArrayDeque<>(List.

Continue reading »

Session Management: Fixation, Concurrency, and Redis Sessions

How Spring Security Uses Sessions For form login and traditional web applications, Spring Security stores the Authentication object in the HTTP session. On every request, SecurityContextPersistenceFilter (Spring Security 5) or SecurityContextHolderFilter (Spring Security 6) loads the SecurityContext from the session and puts it in the SecurityContextHolder. For stateless APIs using JWT or OAuth2 Bearer tokens, no session is created — the token is verified on every request. Session Creation Policy Control when Spring Security creates sessions:

Continue reading »

Setting Up Java 11: JDK Options, Maven/Gradle, and IDE Configuration

Choosing a JDK Distribution Java 11 is available from multiple OpenJDK distributions. All are TCK-certified and binary-compatible; the differences are support timelines and add-ons. Distribution Vendor Java 11 Support Until Notes Eclipse Temurin Adoptium Oct 2027 Community standard, most downloaded Amazon Corretto Amazon Aug 2024 (free), extended via AWS Best choice for AWS workloads Azul Zulu Azul Systems 2026+ Wide platform coverage Microsoft Build of OpenJDK Microsoft 2024 Best for Azure Oracle JDK 11 Oracle Oct 2024 (free LTS) Commercial support until 2026 GraalVM CE 21 Oracle/GraalVM Community Native image + polyglot; JDK 21-based For most teams: Eclipse Temurin 11 — widest platform support, longest free support window, backed by a vendor-neutral foundation.

Continue reading »

Setting Up Java 17: JDK Options, Tooling, and IDE Configuration

JDK Distribution Options Multiple vendors ship Java 17 JDK builds. All pass the TCK (Technology Compatibility Kit) — they are functionally equivalent for development. Distribution Provider Notes Eclipse Temurin Adoptium / Eclipse Recommended default; fully open-source Amazon Corretto AWS Free; optimized for AWS Lambda and EC2 Microsoft Build of OpenJDK Microsoft Windows and Azure optimized Oracle JDK 17 Oracle Free for development; commercial license for production Azul Zulu Azul Commercial support available; free binaries GraalVM CE 22.

Continue reading »

Setting Up Java 21: JDK Options, Tooling, and IDE Configuration

Choosing a JDK Distribution Java 21 is open source (OpenJDK). Multiple vendors distribute binaries, all built from the same source with identical features. Choose based on your support requirements: Distribution Vendor Free LTS Support Notes Eclipse Temurin Adoptium Yes 2028+ Recommended for most developers OpenJDK Oracle/Community Yes 6 months only Reference implementation, no LTS Oracle JDK Oracle Yes (NFTC) 2031 Identical to OpenJDK since Java 17 Amazon Corretto AWS Yes 2030+ Good for AWS deployments Microsoft Build of OpenJDK Microsoft Yes Long-term Good for Azure deployments Azul Zulu Azul Yes/Paid Long-term Includes Zing JVM variant GraalVM Oracle Yes Long-term Adds native-image, polyglot Recommendation: Eclipse Temurin for local development; match your cloud provider’s JDK for production (Corretto on AWS, Microsoft OpenJDK on Azure).

Continue reading »

Setting Up Java 8: JDK Options, Maven/Gradle, and IDE Configuration

Choosing a Java 8 Distribution Getting your environment right before writing a single line of code saves hours of debugging compiler errors and version conflicts later. This article covers every distribution option, all three major build tools, and both popular IDEs — including the specific settings that trip up most developers when first configuring Java 8. Oracle stopped providing free Java 8 updates for commercial use in January 2019. Multiple vendors now ship free, production-quality Java 8 builds:

Continue reading »

Setting Up Spring Boot with Spring Data JPA and MySQL

Introduction This article builds the project foundation used throughout the entire series. By the end, you will have a running Spring Boot 3.3 application connected to MySQL 8.x with Hibernate 6, a proper connection pool, schema management via Flyway, and SQL logging configured so you can see exactly what Hibernate sends to the database. Project Setup Maven pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.

Continue reading »