Demos, Demos, Demos

A list of the demo projects I created for various posts and videos - they include the snippets shown therein and then some. Now they wait for you to try them out.

A fair share of my posts demonstrate how to use Java language features, how to get the most out of APIs, how to implement a pattern in modern Java, and so forth. For most of them I created dedicated demo projects and here's a list of them.

So if you're the kind of person who prefers to learn from code rather than blog posts or videos, why not check them out and play with the code yourself?

Java X Demo

A project showcasing all important Java 9-16 features

Here's a list of the posts that reference it:

Image with slug talk-java-x
Java 22 - Better Language, Better APIs, Better Runtime#talk#java‑22
Java 21 was an explosive release, but 22 is no slouch either: Unnamed patterns, stream gatherers, multi-source-file launcher plus many new and improved features in preview
Image with slug implementing-gatherers
Implementing New Java Stream Operations#video#streams
Implementing a bunch of Gatherers to better understand the proposed addition to the stream API
Image with slug inside-java-newscast-57
Better Java Streams with Gatherers - Inside Java Newscast #57#video#streams
Stream::gather is a new intermediate meta-operation that allows the JDK and us to implement all kinds of intermediate operations as Gatherers without overloading the Stream interface
Image with slug java-16-guide
Definitive Guide To Java 16#post#java‑16
A detailed guide to Java 16: records, type patterns, sealed classes; Stream and HTTP/2 additions, Unix domain socket support; Project Panama previews, packaging tool, performance improvements, and more
Image with slug java-unix-domain-sockets
Code-First Unix Domain Socket Tutorial#post#java‑16
Java's socket channel / server-socket channel API can use Unix domain sockets for faster and more secure inter-process communication on the same host
Image with slug java-type-pattern-matching
Type Pattern Matching with instanceof#post#java‑16 #java‑basics #pattern‑matching
Type patters with instanceof are Java's first step towards pattern matching. Motivation, syntax, details, and future applications - here's all you need to know.
Image with slug java-16-stream-mapmulti-group
Broken Stream::group with Java 16's mapMulti#post#java‑16 #streams
Java 16 adds a new method mapMulti to Stream and it can be abused to simulate a reverse-flatMap aka group operation (with shortcomings).
Image with slug java-16-stream-mapmulti
Faster flatMaps with Stream::mapMulti in Java 16#post#java‑16 #streams #performance
Java 16 adds a new method mapMulti to Stream. It fills the same role as flatMap, but is more imperative - and faster.
Image with slug java-13-guide
Definitive Guide To Java 13#post#java‑13
A detailed guide to Java 13: text blocks, switch expressions with yield, ZGC, dynamic AppCDS archives
Image with slug java-application-class-data-sharing
Improve Launch Times On Java 13 With Application Class-Data Sharing#post#java‑10 #java‑12 #java‑13 #performance
On Java 10+, you can use application class-data sharing to reduce launch times, response time outliers, and memory footprint. By archiving class data with -Xshare:dump and loading it with -Xshare:on, the JVM's class loading workload can be reduced considerably.
Image with slug java-13-switch-expressions
Definitive Guide To Switch Expressions In Java 13#post#java‑13 #java‑basics #switch
Java 13 finalized switch expressions. Together with a new lambda-style arrow syntax, this makes switch more expressive and less error-prone.
Image with slug java-13-text-blocks
Definitive Guide To Text Blocks In Java 13#post#java‑13 #java‑basics
Java 13 introduces text blocks: string literals that span multiple lines. Learn about syntax, indentation, escape sequences, and formatting.
Image with slug java-12-guide
Definitive Guide To Java 12#post#java‑12 #migration
Detailed Java 12 guide: migration, versions; switch expressions, teeing collectors, indenting/transforming strings (and more); default CDS, Shenandoah, G1.
Image with slug java-12-teeing-collector
Teeing Collector in Java 12#post#java‑12 #streams
The teeing collector, available since Java 12 as Collectors::teeing, forwards its input to two other collectors before merging their results with a function.
Image with slug java-12-experiments
Java 12 Experiments (Live Stream)#video#java‑12
In my first live stream ever (yay!), we explored Java 12's API improvements
Image with slug java-11-gems
Eleven Hidden Gems In Java 11#post#java‑11
Eleven small but shiny additions in Java 11 to classes like String, Path, Files, Collection, Optional, and others that make coding a little more elegant.
Image with slug talk-java-var
Fun With var#talk#anonymous‑classes #default‑methods #generics #lambda #java‑10 #var
A live-coding talk where I show off all you need to know about var in Java. And then some.
Image with slug scripting-java-shebang
Scripting Java 11, Shebang And All#post#java‑11 #tools #on‑ramp
On Java 11+, you can run a single source file without compiling it. Beyond experimentation, you can write scripts this way. Even shebang is supported!
Image with slug java-reactive-http-2-requests-responses
Reactive HTTP/2 Requests And Responses In Java 11#post#java‑11
With Java 11's new reactive HTTP/2 API, request and response bodies can be handled with reactive streams: you can throttle, stream, and cancel early.
Image with slug java-12-switch-expression
First Contact with Switch Expressions in Java 12#video#java‑12 #switch
With Java 12, switch is no longer just a statement, but becomes an expression. Let's take a look!
Image with slug java-http-2-api-tutorial
Java 11 HTTP/2 API Tutorial#post#java‑11 #java‑basics
Tutorial for Java 11's new HTTP/2 API with HttpClient, HttpRequest, and HttpResponse at its center. Shows synchronous and asynchronous request handling.
Image with slug java-var-traits
Unlocking Traits With var#post#default‑methods #java‑10 #lambda #var
In Java 10, var makes it is possible to ad-hoc combine traits into an instance that matches your exact requirements. Alas, it has some downsides.
Image with slug java-var-anonymous-classes-tricks
Tricks with var and anonymous classes (that you should never use at work)#post#anonymous‑classes #java‑10 #var
Local-variable type inference with var makes it easier to work with anonymous classes, e.g. for ad-hoc fields and methods. Don't do it, though!
Image with slug java-var-intersection-types
Unlocking Intersection Types With var#post#generics #java‑10 #var
Java 10's var makes intersection types in Java more approachable. Generics tricks are still needed, but var makes it easy to declare such variables.
Image with slug multi-release-jars-multiple-java-versions
How To Use Multi-release JARs To Target Multiple Java Versions#post#tools #java‑9
Multi-release JARs allow you to create a single JAR that contains bytecode for several Java versions with jar --version 9 (or 10, or...). Presented with a multi-release JAR, JVMs version 9 and later will load the code that was included for their version.
Image with slug java-9-tutorial
Code-First Java 9 Tutorial#post#java‑9 #migration #streams #optional #collections #j_ms
Showing code for the most important Java 9 features: private interface methods, stream and optional APIs, collection factories, reactive streams, stack walking, multi-release JARs, redirected platform logging, unified logging, the module system, and more. If you're new to Java 9, start here.
Image with slug java-10-var-type-inference
First Contact With 'var' In Java 10#post#java‑10 #java‑basics #var
Java 10 introduces the var keyword, which lets the compiler infer local variable types. Here's how var works, why it exists, how it impacts readability.
Image with slug var-java-10
First contact with var in Java 10#video#java‑10 #var
How to use var, where it works and where it doesn't (and why), and how it might impact readability
Image with slug java-unified-logging-xlog
Unified Logging Of JVM Messages With The -Xlog Option#post#java‑9 #java‑basics
Java 9 introduces unified logging, a central mechanism configurable with -Xlog to observe class loading, threading, garbage collector, module system, etc.
Image with slug welcome-java-9
Welcome, Java 9!#video#community #java‑9
Java 9 is out today and with other members of the community I'm throwing a welcome party. Get an all around view on the new Java release with various opinions, tips, and great sources!
Image with slug java-9-optional
Java 9 Additions To Optional#post#java‑9 #optional
Java 9 is coming! One of the changes are new methods on Optional: stream(), or(), and ifPresentOrElse(), which considerably improve Optional's API.
Image with slug java-9-stream
Java 9 Additions To Stream#post#java‑9 #streams
Java 9 is coming! One of the many changes are new Stream methods: takeWhile, dropWhile, and ofNullable. For more fun with streams!
Image with slug java-default-methods-interface-evolution-failure
Interface Evolution With Default Methods – Part II: Interfaces#post#default‑methods #generics #java‑8
Why interface evolution with default methods does not work for whole interfaces - at least not smooth enough to be practical.

Modern Java in Action

A GitHub Crawler with everything Java (21) has to offer

Here's a list of the posts that reference it:

Image with slug talk-java-action
Modern Java in Action#talk#java‑21 #virtual‑threads #pattern‑matching #records
Let's write a GitHub Crawler and let's throw in everything Java (22) has to offer

Loom Lab

Experiments with Project Loom's virtual threads and structured concurrency

Here's a list of the posts that reference it:

Image with slug inside-java-newscast-34
Loom in the Java Ecosystem - Inside Java Newscast #34#video#java‑19 #project‑loom #libraries
Among other things, Java 19 ships with virtual threads, structured concurrency APIs, sealed types, and pattern matching in switch - all of them as previews, but still very cool! I'm using these features here to create a GitHub crawler.
Image with slug inside-java-newscast-33
Java 19 in Action - Inside Java Newscast #33#video#java‑19 #project‑loom
Among other things, Java 19 ships with virtual threads, structured concurrency APIs, sealed types, and pattern matching in switch - all of them as previews, but still very cool! I'm using these features here to create a GitHub crawler.

Module System Woes

Common problems that pop up in modularized projects and their solutions or workarounds

Here's a list of the posts that reference it:

Image with slug talk-java-modules-irl
Java Modules in Real Life#talk#j_ms #migration
Advice on why, when, when not, and how to use Java modules in real life for your projects

J_MS Monitor

An example project making full use of the Java module system and all its features

Here's a list of the posts that reference it:

Image with slug build-modules
Java Modules Cheat Sheet#post#j_ms #java‑9 #java‑11
A cheat sheet for building and running Java modules from the command line with javac, jar, and java
Image with slug java-module-system-tutorial
Code-First Java Module System Tutorial#post#java‑9 #java‑basics #j_ms
Tutorial of Java 9 module system basics: declare modules with, compile, package, launch them, learn of module path and readability graph.
Image with slug java-modules-optional-dependencies
Optional Dependencies with requires static#post#java‑9 #j_ms
The Java Platform Module System allows optional dependencies with requires static. They are accessible at compile but can be absent at run time.
Image with slug talk-java-module-system
The Java Module System Beyond The Basics#talk#j_ms #migration
In this talk, I go beyond the module system basics and present more advanced features for those who want to become their team's module system expert
Image with slug java-modules-implied-readability
Implied Readability With requires transitive#post#java‑9 #j_ms
In Java 9 a module must read another to use its API. With implied readability a 3rd module passes the dependency on, allowing the 1st to read the 2nd.

Java After Eight

A real-life code base, initially on Java 8, that invites an update to Java 15 and to the many new language features, additional and improved APIs, and JVM capabilities

Here's a list of the posts that reference it:

Image with slug talk-java-after-n
Java After Seventeen#talk#java‑17 #java‑18 #java‑19 #java‑20 #java‑21
A live-coding talk during which I update a Java 11/17 code base to Java 21, making good use of new language features, additional and improved APIs, and JVM capabilities

Effective Java

A code base with examples, tests, and benchmarks for my YouTube series on Effective Java, Third Edition

Here's a list of the posts that reference it:

Image with slug effective-java-utilities-singleton-dependency-injection
Utilities, Singletons and Dependency Injection - Effective Java, Items 3-5#video#book‑club #patterns
Mildly surprising (to me), it makes sense to discuss these three patters in one video - so here it goes
Image with slug effective-java-builders
Use Builders... Cautiously - Effective Java, Item 2#video#book‑club #patterns
Why and how to avoid the builder pattern and how to make best use of it if you can't
Image with slug effective-java-static-factory-methods
Static Factory Methods - Effective Java, Item 1#video#book‑club #patterns
How to use static factory methods to overcome three shortcomings of constructors
Image with slug effective-java-kickoff
Kicking off a series on Effective Java, Third Edition#video#book‑club
Kick-off to
a YouTube series on Effective Java, Third Edition - let's find some angles Josh didn't cover

Java 9/11 Migration

A Java 8 code base that causes some migration challenges when updated to Java 9/11

Here's a list of the posts that reference it:

Image with slug java-11-migration-guide
All You Need To Know For Migrating To Java 11#post#java‑11 #migration
Migrating from Java 8 to Java 11? This has got you covered: licensing, long-term support, preparations, version requirements, migration challenges, and more.
Image with slug five-command-line-options-hack-java-module-system
Five Command Line Options To Hack The Java Module System#post#java‑9 #j_ms
Get your code running on the Java 9 Module System with the command line options --add-exports, --add-opens, --add-modules, --add-reads, and --patch-module.
Image with slug talk-java-9-migration
To JAR Hell And Back#talk#java‑9 #java‑11 #j_ms #migration
A live-coding talk where we take a typical Java 8 code base and update it to Java 9 and beyond, overcoming some common and some less common hurdles like dependencies on internal APIs and split packages
Image with slug java-9-migration-guide
Java 9 Migration Guide: The Seven Most Common Challenges#post#java‑9 #j_ms #migration
Solutions to the seven most common challenges for a Java 9 migration. Each of them explained with background, symptoms, and fixes.

JUnit 5 Demo

A demo showing off all essential and many advanced JUnit 5 features

Here's a list of the posts that reference it:

Image with slug junit-5-basics
JUnit 5 Basics: @Test, Lifecycle, Assertions, Assumptions, And More#post#java‑basics #junit‑5 #libraries #testing
The Basics of JUnit 5: How to use @Test, @BeforeAll, @BeforeEach, @AfterEach, @AfterAll, assertions, and assumptions. How to disable, name, and tag tests.
Image with slug junit-5-architecture-jupiter
JUnit 5 Architecture or "What's Jupiter?"#post#architecture #junit‑5 #libraries #testing
The JUnit 5 architecture promotes a better separation of concerns than JUnit 4 did. It also provides clear APIs for testers (Jupiter) and tools (Platform).
Image with slug junit-5-disabled-conditions
JUnit 5 Conditions: @Enabled, @Disabled, Customized#post#junit‑5 #libraries #testing
A detailed look at JUnit 5's @Disabled, @DisabledOnOs, @DisabledOnJre, etc. and how to create custom conditions to flexibly disable test methods.
Image with slug junit-5-dynamic-tests
JUnit 5 - Dynamic Tests#post#junit‑5 #lambda #libraries #testing
With JUnit 5's dynamic tests, we can create tests at run time, for example to parameterize tests, create hierarchical test plans, or define tests with lambdas.
Image with slug junit-5-extension-model
JUnit 5 Extension Model: How To Create Your Own Extensions#post#architecture #junit‑5 #libraries #testing
The JUnit 5 extension model enables detailed, flexible, and powerful additions to JUnit 5's core features. For that it provides specific extension points.
Image with slug junit-5-parameterized-tests
JUnit 5 - Parameterized Tests#post#junit‑5 #libraries #testing
Thorough introduction to parameterized tests in JUnit 5 with @ParameterizedTest, argument sources (eg @MethodSource, @CsvSource), and argument converters.
Image with slug junit-5-setup
JUnit 5 Setup in IntelliJ, Eclipse, Maven, and Gradle#post#tools #junit‑5 #libraries #testing
How to set up JUnit 5 so tests run in IntelliJ, Eclipse, Maven, Gradle or, if all else fails, via JUnit 4 or on the command line.
Image with slug junit-5-parameterized-tests-nighthacking
Parameterized Tests in JUnit 5#video#junit‑5
At JavaLand 2017, I spent 15 minutes exploring JUnit 5's (then) brand-new parameterized test feature in a NightHacking session
Image with slug talk-junit-5
JUnit 5#talk#junit‑5 #testing
In this talk, I introduce JUnit 5 from basic tests to more advanced features like nesting, parameterization, parallelization, and extensions. We also discuss its architecture and compatibility with JUnit 4.

Maven Java 9+

Different ways to build projects on Java 9 and later with Maven

Here's a list of the posts that reference it:

Image with slug maven-on-java-9
Maven on Java 9 and later - Six Things You Need To Know#post#java‑9 #tools
How to use the compiler executable, toolchains, and mavenrc to run Maven on Java 9 and how to use mvn/jvm.config and profiles to configure your build.

JSR 305 on Java 9+

An exploration into various ways of getting JSR 305 to work on Java 9

Here's a list of the posts that reference it:

Image with slug jsr-305-java-9
Making JSR 305 Work On Java 9#post#java‑9 #j_ms #migration
Using annotations from JSR-305 (@Nonnull, @Nullable) and javax.annotation (@Generated, @PostConstruct) on Java 9 causes a split package. Here's the fix.

Jigsaw vs Reflection

An experiment with Project Jigsaw's encapsulation and reflection

Here's a list of the posts that reference it:

Image with slug java-modules-reflection-vs-encapsulation
Reflection vs Encapsulation#post#java‑9 #j_ms #project‑jigsaw #reflection
Reflection wants to break into all code; encapsulation wants to give modules a safe space. How can this stand off be resolved?

JUnit Lambda Lab

An experiment with the JUnit Lambda prototype

Here's a list of the posts that reference it:

Image with slug junit-lambda-prototype
JUnit Lambda - The Prototype#post#junit‑5 #libraries #testing
JUnit Lambda will eventually bring us JUnit 5. This is a discussion of the recent prototype, its features, core principles and compatibility considerations.

Benchmark Lab

A collection of various JMH-based Java benchmarks

Here's a list of the posts that reference it:

Image with slug java-stream-performance-your-ideas
Stream Performance - Your Ideas#post#java‑8 #performance #streams
Another post about stream performance - this one implements your ideas about how else to approach the topic.
Image with slug java-stream-performance
Stream Performance#post#java‑8 #performance #streams
A close look at stream performance. How do they compare to for and for-each loops oder arrays and lists. And what role plays boxing?

Pirate-Elvis Operator

A small project containing the Pirate-Elvis operation and some example uses

Here's a list of the posts that reference it:

Image with slug java-pirate-elvis-operator
Roll Your Own Pirate-Elvis Operator#post#java‑8 #lambda #optional
Java has no Elvis operator (or null coalescing operator / null-safe member selection) but with lambda expressions / method references you can roll your own.

Javadoc 8 Tags

A demo showing @apiNote, @implSpec, and @implNote in action, including the necessary additions to Maven's pom.xml and the generated javadoc

Here's a list of the posts that reference it:

Image with slug javadoc-tags-apiNote-implSpec-implNote
New Javadoc Tags @apiNote, @implSpec, and @implNote#post#java‑8 #tools
There are new Javadoc tags used in Java 8: @apiNote, @implSpec, and @implNote. Take a look at their history, meaning and use on command line and with Maven.

Instances of Non-Capturing Lambdas

An exploration into the JVM's reuse of non-capturing lambda expression instances

Here's a list of the posts that reference it:

Image with slug java-non-capturing-lambdas
Instances of Non-Capturing Lambdas#post#default‑methods #java‑8 #lambda
See how Java's creation of instances of non-capturing lambda expressions can lead to unexpected and possibly bug-inducing behavior.

Serialize Optional

A demo showing how to use the serialization proxy pattern to serialize Optional instances

Here's a list of the posts that reference it:

Image with slug serialize-java-optional
Serialize Optional#post#java‑8 #optional #serialization
A summary of why you can't serialize Optional and what can be done to deal with that limitation if necessary.

Serialization Proxy Pattern

A demo of the serialization proxy pattern

Here's a list of the posts that reference it:

Image with slug java-serialization-proxy-pattern
The Serialization Proxy Pattern#post#clean‑code #patterns #serialization
A presentation of the Serialization Proxy Pattern as defined in Effective Java. It defines the pattern, describes its implementation and gives examples.

Decorator Pattern With Java 8

A demo of how to better use the decorator pattern with Java 8 features

Here's a list of the posts that reference it:

Image with slug decorator-pattern-default-methods
The Decorator Pattern With Default Methods#post#clean‑code #patterns #default‑methods #java‑8
Use Java 8's default methods to make the decorator pattern even more beautiful, which results in more concise and readable code.