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-13 features

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

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).
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.
Definitive Guide To Java 13#post#java‑13
A detailed guide to Java 13: text blocks, switch expressions with yield, ZGC, dynamic AppCDS archives
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.
Definitive Guide To Switch Expressions In Java 13#post#java‑12 #java‑13 #java‑basics
Java 12 introduces switch expressions. Together with a new lambda-style arrow syntax, this makes switch more expressive and less error-prone.
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.
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.
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.
Java 12 Experiments (Live Stream)#video#java‑12
In my first live stream ever (yay!), we explored Java 12's API improvements
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.
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.
Scripting Java 11, Shebang And All#post#java‑11 #tools
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!
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.
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!
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.
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.
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!
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.
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.
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.
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.
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
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.
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!
Java 16 Is Coming!#talk#java‑9 #java‑10 #java‑11 #java‑12 #java‑13 #java‑14 #java‑15
In this talk, I introduce the Java language features, new/updated APIs, and new JVM capabilities that recent Java releases brought to the ecosystem
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.
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!
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.

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:

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
Code-First Java Module System Tutorial#post#java‑9 #java‑basics #j_ms
Tutorial of Java 9 module system basics: declare modules with module-info.java, compile, package, launch them, learn of module path and readability graph.
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.
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
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:

Java After Eight#talk#java‑9 #java‑10 #java‑11 #java‑12 #java‑13 #java‑14 #java‑15
A live-coding talk during which I update a Java 8 code base to Java 15, 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:

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
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
Static Factory Methods - Effective Java, Item 1#video#book‑club #patterns
How to use static factory methods to overcome three shortcomings of constructors
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:

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.
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.
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
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:

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).
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.
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.
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.
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.
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.
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.
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
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:

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:

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:

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:

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:

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.
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:

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:

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:

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:

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:

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:

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.