What Are Method References? Method references are a signal to the reader: “this lambda does exactly one thing — it calls this existing method.” When the entire body of a lambda is a single method call, replacing it with a method reference removes noise without losing information. Knowing which of the four kinds to apply in each context is what separates fluent Java 8 code from code that merely uses the syntax.
Continue reading »Java8
19 posts in this section
Migrating to Java 11: From Java 8 — Step by Step
Migration Overview Migrating from Java 8 to Java 11 is the most common Java upgrade scenario. The migration has two distinct phases: Make it compile and run — fix incompatibilities introduced by Java 9–11 Modernise the code — adopt var, List.of(), String.isBlank(), and other new APIs Phase 1 is mandatory and blocks the upgrade. Phase 2 is optional and can happen incrementally. This guide focuses entirely on Phase 1. The 10-Step Migration Checklist [ ] 1.
Continue reading »Migrating to Java 17: From Java 8 and Java 11 — Step by Step
Why Migrate to Java 17? Java 17 is the current recommended enterprise LTS. Key reasons to migrate now: Spring Boot 3.x requires Java 17 — the entire Spring ecosystem is moving here Java 11 extended support ends around 2026 depending on your vendor Java 8 mainstream support ended in 2019; extended support ended 2030 for Oracle JDK but active vulnerability exposure is increasing Language features: Records, Sealed Classes, Text Blocks, Pattern Matching, Switch Expressions — all available in Java 17 Security: Strong JDK encapsulation closes years of internal API exposure used in exploits Recommended Migration Path Java 8 → Java 11 → Java 17 Do not jump directly from Java 8 to Java 17 in one step if your codebase is large or has many third-party dependencies.
Continue reading »Migrating to Java 21: From Java 8, 11, and 17 — Step by Step
Why Migrate Now? Java 21 is the current Long-Term Support (LTS) release, and it is the most feature-rich LTS since Java 8. LTS releases receive security patches and bug fixes for years. Java 11, the previous widely-used LTS, reached its extended support window end depending on your vendor. Java 8 mainstream support ended in 2019. More concretely, Java 21 brings: Virtual Threads — drop-in replacement for platform threads, enabling massive concurrency without reactive rewrites Pattern Matching for switch and records — eliminating entire categories of verbose, error-prone instanceof/cast chains Sequenced Collections — a unified API for ordered collection types Generational ZGC — sub-millisecond GC pauses at any heap size These are not incremental improvements.
Continue reading »New APIs: Base64, StringJoiner, Spliterator, Files.lines, StampedLock, Nashorn
Base64 Before Java 8, Base64 encoding required a third-party library (Apache Commons Codec, Guava) or the internal sun.misc.BASE64Encoder class — an API that was never officially supported and was deliberately restricted from Java 9 onwards. Java 8 standardised encoding in java.util.Base64, which covers standard, URL-safe, and MIME variants and can wrap streams for large payloads. Java 8 added java.util.Base64 to the standard library. Three Encoders // Standard Base64 (RFC 4648) Base64.
Continue reading »Optional: Eliminating NullPointerException the Right Way
The Problem Optional Solves NullPointerException is the most common runtime exception in Java, and it is almost always avoidable. Optional<T> is not a magic fix — used incorrectly it becomes a more verbose null check. Used correctly, it encodes the possibility of absence directly in the type system, so callers can never “forget” to handle the empty case. This article covers both how to use Optional and — critically — how not to.
Continue reading »Parallel Streams: ForkJoinPool, Spliterators, and When NOT to Parallelize
How Parallel Streams Work Parallel streams are one of Java 8’s most misused features. It is tempting to add .parallel() to any slow stream pipeline, but the performance characteristics are counterintuitive: parallel can make things slower for small data, and adding blocking I/O inside a parallel stream can stall the entire JVM. This article explains the mechanics, the cases where parallel genuinely helps, and the patterns to avoid. A parallel stream splits its source into sub-sequences, processes each sub-sequence on a separate thread, and merges the results.
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 »Streams API: Lazy Pipelines and the Functional Data Model
The Problem Streams Solve Java loops are not wrong — they are often the right tool. But when a computation is a multi-step pipeline of filter → transform → aggregate, a loop hides the structure of the computation in a tangle of temporary variables and mutated collections. The Streams API makes the structure explicit, lets the JVM optimise it, and composes naturally with lambdas and method references. Consider filtering a list of orders to find the names of active premium customers who spent over $500, sorted alphabetically:
Continue reading »