Java9

6 posts in this section

Collection Factory Methods (JEP 269): Immutable List, Set, and Map

Why Collection Factory Methods? Before Java 9, creating a small immutable collection was tedious: // Java 8 — three lines, two classes, mutable intermediate List<String> names = Collections.unmodifiableList( Arrays.asList("Alice", "Bob", "Charlie") ); // Java 8 — even worse for Map Map<String, Integer> scores = new HashMap<>(); scores.put("Alice", 90); scores.put("Bob", 85); Map<String, Integer> immutableScores = Collections.unmodifiableMap(scores); JEP 269 (Java 9) introduced static factory methods that create truly immutable collections with a single expression:

Continue reading »

Garbage Collection: G1GC, ZGC, Epsilon, and AppCDS

GC Changes Across Java 9–11 Release Change JEP Java 9 G1GC becomes the default GC JEP 248 Java 9 Unified GC logging (-Xlog:gc*) JEP 271 Java 10 Parallel Full GC for G1 JEP 307 Java 10 Application Class-Data Sharing (AppCDS) JEP 310 Java 11 Epsilon: No-Op GC JEP 318 Java 11 ZGC: Scalable Low-Latency GC (experimental) JEP 333 G1GC as Default (JEP 248, Java 9) G1 (Garbage-First) replaced Parallel GC as the default on systems with ≥2 CPUs and ≥2 GB heap.

Continue reading »

Java 11 Overview: The Road from Java 8 Through Java 9, 10, to LTS

Why Java 11 Matters Java 8 was released in March 2014. It dominated enterprise Java for nearly a decade, but it misses a decade’s worth of language improvements, API modernisation, JVM advances, and security hardening. Java 11 (September 2018) is the first Long-Term Support release after Java 8, and it packages three releases of evolution into a single supported baseline. For most teams the question is not whether to upgrade, but how.

Continue reading »

Module System (JPMS, JEP 261): Project Jigsaw Deep Dive

The Problem JPMS Solves Before Java 9, the JDK had no real notion of encapsulation at the library level. public meant accessible to everyone — including internal JDK classes like sun.misc.Unsafe and com.sun.internal.*. Large codebases suffered from: No reliable encapsulation: Any public class in any JAR was reachable from any other JAR. Classpath hell: Duplicate or conflicting classes from different JARs led to unpredictable behaviour. Monolithic JDK: The entire 60+ module JDK had to ship with every application.

Continue reading »

Stream & Optional API Enhancements (Java 9–11)

Stream API — New Methods (Java 9) Java 9 added four new instance methods to Stream<T>. All are terminal-ish or intermediate operations that make common patterns expressible without workarounds. takeWhile(Predicate) Returns elements from the beginning of the stream as long as the predicate holds, then stops. The first element that fails the predicate (and all subsequent elements) are discarded. Stream.of(1, 2, 3, 4, 5, 1, 2) .takeWhile(n -> n < 4) .

Continue reading »

Tooling: JShell, jlink, and Single-File Programs (JEP 222, 282, 330)

Overview Java 9 and 11 added three tools that change how you write, test, and deploy Java code: Tool JEP Release Purpose JShell JEP 222 Java 9 Interactive REPL for Java code jlink JEP 282 Java 9 Build minimal custom JRE images Single-file programs JEP 330 Java 11 Run .java files directly JShell — Interactive Java REPL JShell is Java’s Read-Eval-Print Loop: a command-line tool for evaluating Java expressions, statements, methods, and classes interactively, without creating a project.

Continue reading »