Language selector

Posts

Java 22 is about to be released tomorrow. There are many super nice things in this release. I suspect making Project Panama’s native/foreign calls will make many people’s life easier, as well as ongoing changes to concurrency, string templates and finally being able to call something before super. However, there’s one thing I guess is going to be my (almost) hidden hero of Java 22. Folks, I introduce to you Gatherers.
In the past I wrote two posts about Java sripts and their portability using shebang. As far as I can tell everything in these two installments is still valid, only now, in Java 21, thanks to JEP-445 things can be even simpler. In this post I’ll try to describe fist the changes introduced by this JEP, then go deeper on how they relate to the “scripts in Java”. I’m going to cover how you can simplify your main method, get rid of the class surrounding it, and even show you when it won’t work.
As I wrote in my previous post I had issues running code using JEP 443 using tools like Maven, Gradle or IntelliJ IDEA. Thanks to the one and only Tagir Valeev the solution is quite simple. Upgrade to JDK 21.0.1. And that’s it ;-) No need to touch anything else. If you fancy more explanation, please follow on this Twitter thread. And we shall all remember that upgrading is a good thing, because we’re not going to stay on Java 8 forever, right?
Update The issue has been solved, please go to the post with solution. Note: I’m leaving the original post below in case someone bumps to a similar issue in the future. Sometimes it’s easier to search using the problem ;-) While preparing my Deep Dive talk on Java 21 for friendly Java User Groups, I’ve noticed a curious case of JEP 443: Unnamed Patterns and Variables (Preview). I’ve managed to create a reproducer, so I’d like to share the findings here.
Let me start this entry with a dad joke. An electron rides a motorcycle. Suddenly, a police officer stops the electron and says: ‘I had to stop you, because you were speeding, driving exactly 178 and half kilometres per hour.’ ‘Well, THANK YOU VERY MUCH, officer!’ the electron says, ‘Now I have absolutely no idea where I am!!!’ Some dad jokes are terrible, and don’t worry if you don’t get this one.
I don’t always run public open trainings, but when I do, I try to run them as charity events. I believe this approach is meaningful and necessary. In this article, I will explain why I find it useful and important. However, let me begin by outlining some rules. Feel free to adopt this idea if you find it appealing. Rules When running an IT charity workshop, I establish the following rules.
Some people complain that they’re not doing integration tests “because they take too much time.” All right, the interaction with real dependencies sometimes can’t be made shorter, but there are surely ways to start the databases, message brokers, and so on faster if you happen to use Testcontainers for that. In this entry, I’ll be using Java. However, since Testcontainers is (from a certain angle) a convenient way to interoperate with Docker-compatible containers using the programming language you know, this should apply to other technology stacks as well.
During my trainings and lectures, I get asked “but how do you switch Java so fast?” or even “it’s possible to have several versions of Java on your computer at the same time?!” Sure it is! The way is very simple: use SDKMAN! I use it almost every day, it comes in handy not only during lectures about the latest versions of Java, but in ordinary daily work when you need to check “how it works on another version”.
During my trainings and lectures, I get asked “but how do you switch Java so fast?” or even “it’s possible to have several versions of Java on your computer at the same time?!” Sure it is! The way is very simple: use SDKMAN! I use it almost every day, it comes in handy not only during lectures about the latest versions of Java, but in ordinary daily work when you need to check “how it works on another version”.
In the previous post we were testing if Java’s Virtual Threads aren’t used in a way that makes them pinned. It’s because we want our Platform Threads (especially those in the ForkJoin Pool Co.) to keep carrying more and more new Virtual Threads, instead of keeping the engine running while VTs are pinned. (At least as long as we can’t provide our own thread pools to carry VTs.) Spoiler alert: we’re going to use Testcontainers and Toxiproxy today!

Language selector