Demonstrates most features that were introduced after Java 8. They are listed below with links that take you to the demos in this repo, the JEPs responsible for introducing the feature, and to other sources if available. These are the categories:
Circled numbers like ⑰ indicate which Java version introduced a feature or a change. A circled X ⓧ indicates an incubating or previewing feature that is not yet standardized - it can be experimented with but is subject to change.
For a more practical approach to many of these features, including some quick code metrics, check my Java After Eight repo. You can find more from me on nipafx.dev as well as on YouTube and Twitch. To get in touch, follow me on Twitter (DMs are open) or join my Discord.
This project requires at least the most recent Java release, at times even early-access builds of upcoming versions.
You can get OpenJDK builds for both directly from jdk.java.net, although I prefer to use SDKMAN to install and manage them.
The project can be built with Maven, i.e. mvn package
.
There are several ways to execute demos:
- If your IDE is up to speed (which may require preview versions or additional plugins), you can execute most demos straight from there.
- If a feature is contained in a single class, you can also use single-source file execution and just call
java $SOURCE_FILE
. - You can always build with
mvn package
and then run any specific class with ...... where $CLASS is the fully qualified name of the class you want to execute.java -p target/java-x.jar -m dev.nipafx.demo.java_x/$CLASS
Depending on the demo you may have to add additional command line flags - this should be listed in the respective file.
For some features, you have to run the .sh
scripts in this repo's root directory to see them in action.
If that's necessary, the feature list below mentions it.
For that to work, you need to ensure that a java
binary from the respective JDK version is available on your path - again, I use SDKMAN for that.
- ⑰ sealed classes (articles 1, 2; JEP 409)
- ⑯
instanceof
pattern matching (articles 1, 2; JEP 394) - ⑯ records (article, JEP 395)
- ⑯ static members of (non-static) inner classes (JDK-8254105)
- ⑮ text blocks (article, JEP 378)
- ⑭ switch expressions (article, video, JEP 361)
- ⑩ local-variable type inference with
var
(article, video, JEP 286): - ⑨ private interface methods (JEP 213)
- ⑨ try-with-resources on effectively final variables (JEP 213)
- ⑨ diamond operator for anonymous classes (JEP 213)
- ⑨
@SaveVarargs
on private non-final methods (JEP 213) - ⑨ no warnings for deprecated imports (JEP 211)
The module system is too big to demo here. Check out the j_ms tag on my blog (for example to find this handy cheat-sheet), the dedicated demo project, a project with solutions to common issues, or my book The Java Module System.
If an API that was introduced in Java 9+ was later updated, the update is listed in the next section.
- ⓧ vector API (JEP 426)
- ⑱ address resolution SPI (JEP 418)
- ⑰ random generator (article, JEP 356, very good Javadoc)
- ⑯ Unix domain sockets (article, JEP-380)
- ⑪ HTTP/2 client (tutorial, reactive request/response bodies):
- ⑨ version API
- ⑨ collection factory methods (JEP 269)
- ⑨ reactive streams (JEP 266)
- ⑨ stack walking (tutorial with benchmarks, JEP 259)
- ⑨ multi-resolution images (JEP 251)
- ⑨ platform-specific desktop features (not supported by my OS so my sample sucks; PRs welcome! JEP 272)
- ⑨ deserialization filter (JEP 290)
- ⓧ Stream gatherers: custom gatherers (videos 1, 2; JEP 461)
- ⑯ (server) socket channels: Unix domain socket support (article, JEP 380)
- ⑯ HTTP/2 client: copying a request
Stream
:- ⑯:
mapMulti
(article 1, 2) - ⑫: teeing collector (article)
- ⑩: to-unmodifiable collector
- ⑨:
takeWhile
,dropWhile
,iterate
,ofNullable
(article)
- ⑯:
String
:- ⑭
@Serial
(Javadoc) - ⑫ formatting numbers
- I/O:
CompletableFuture
:- ⑪
Predicate::not
- ⑪
Pattern::asMatchPredicate
- collections
Optional
:- ⑪:
isEmpty
- ⑩:
orElseThrow
- ⑨:
or
,ifPresentOrElse
,stream
(article)
- ⑪:
- ⑩ version API:
feature()
,interim()
,update()
- ⑨ OS processes (JEP 102)
A few changes have their own articles (in which case they are linked), but many don't. Some of them are show-cased in these posts, though:
- Definitive Guide To Java 13
- Definitive Guide To Java 12
- Eleven Hidden Gems In Java 11
- All You Need To Know For Migrating To Java 11
- Code-First Java 9 Tutorial
- ⑱ external snippets in Javadoc (video, Maven how-to, JEP 413):
- ⑱
jwebserver
, a simple web server (video, JEP 408)
- helpful
NullPointerException
s:- ⑯: enabled by default
- ⑭: introduced (JEP 358)
- ⑬⑫⑩ application class-dara sharing (article, JEP 310, JEP 341, JEP 350)
- ⑪ single-source-file execution
(article,
JEP 330):
- getting started
- echo class
- proper script (run with
cat echo-haiku.txt | ./echo
)
- ⑨ unified logging (article, JEP 158)
- ⑨ multi-release JARs: classes and the script (JEP 238)
- ⑨ platform logging: classes and the script (JEP 264)