13 ms·
JDK 21 Release Notes
- jaimehrubiks 3y agoString templates seems like a basic needed and welcome feature nowadays
- owlstuffing 3y agoA bit late to the party, but yes. Although, in true Java form the designers sacrificed readability to satisfy lesser use-cases. STR.”Total: \{count}” Could not get uglier.
- uzername 3y agoI haven't tried it yet but I'm guessing this will fold into a different visual representation in IntelliJ when the cursor isn't nearby. It's not pretty but if it's consistent I guess it's fine.
- owlstuffing 3y agoI’m using project manifold’s string templates[1] and loving it. 1. https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-strings https://github.com/manifold-systems/manifold/tree/master/man...
- avgcorrection 3y ago> I haven't tried it yet but I'm guessing this will fold into a different visual representation in IntelliJ when the cursor isn't nearby. sigh
- freedomben 3y agoEww, you're not kidding, that's awful. Java is my most ambivalent language. There's things I love, and things I hate, and when it's good it's really good, when it's bad ... Yuck. That said, I do think Python went worse with f-strings. Would have loved to see Java look to Groovy for inspiration.
- ryangs 3y agoIt looks so bad in the context they give themselves: C# $"{x} plus {y} equals {x + y}" Visual Basic $"{x} plus {y} equals {x + y}" Python f"{x} plus {y} equals {x + y}" Scala s"$x plus $y equals ${x + y}" Groovy "$x plus $y equals ${x + y}" Kotlin "$x plus $y equals ${x + y}" JavaScript `${x} plus ${y} equals ${x + y}` Ruby "#{x} plus #{y} equals #{x + y}" Swift "\(x) plus \(y) equals \(x + y)" And finally: Java STR."\{x} plus \{y} equals \{x + y}"
- hibikir 3y agoIt's explained if you look at the proposals: They wanted to avoid any and all risks of backwards compatibility with any existing templating tool in the Java ecosystem. Every sensible syntax was covered by one of those, so the core language is stuck with the least bad one available.
- paulddraper 3y ago...at what cost tho
- capableweb 3y agoThe JEP makes it kind of clear: > trading off a small amount of convenience to gain a large amount of safety
- paulddraper 3y ago*large *small
- bcrosby95 3y agoYou can create json and sql string template processors that suffer from no injection problems. I'd call that a large improvement over, for example, Javascript. But I'm not familiar enough with the string template feature in the other languages to comment on their relative security.
- ivan_gammel 3y agoAs a reminder, you still can make it $.”…” in your code, if you wish.
- samus 3y agoIt makes perfect sense if you consider that String Templates don't just support interpolation, but also /escaping/ of values. Therefore, Java's existing syntax for escaping stuff is the obvious choice for consistency reasons. If interpolation is all you want, use `STR`. In the future, we will see libraries with template processors for regex patterns, SQL, XML, etc.
- java-man 3y agoVirtual threads are going to make a lot of code much simpler.
- ye-olde-sysrq 3y agoExcellent! With virtual threads, all the blocking code I wrote is efficient now :) Less-joking: I'm so excited for this to start getting adoption. For a pre-release/preview feature, Loom already has SO much traction, with most major frameworks already having support for running app/user code on virtual threads and one notable project (Helidon Nima) replacing netty with their own solution based on blocking IO and virtual threads. Now I want to see the community run with it. I've always thought async IO was just plain gross. Python's implementation is so yucky that after using it for one project I decided that I'd rather DIY it with multiprocessing than use async again. (I don't have any more constructive feedback than that, my apologies, it was a while ago so I don't remember the specifics but what has lasted is the sour taste of the sum of all the problems we had with it - perhaps notably that only about 2 people on my dev team of 5 actually understood the async paradigm). netty did it fine. I've built multiple projects on top of netty and it's fine. I like event-based-async more than async-await-based-async. But it's still a headache and notably I really rather missed the kinds of guarantees you can get (in blocking code) by wrapping the block in try-catch-finally (to e.g. guarantee resources get freed or that two counters, say a requests-in and a requests-out, are guaranteed to match up). But dang am I excited to not do that anymore. I have one specific project that I'm planning to port from async to blocking+virtualthreads that I expect to greatly simplify the code. It has a lot of requests it makes back and forth (it has to manually resolve DNS queries among other things) so there's good chunks of 50-200 ms where I have to either yield (and has gross async code that yields and resumes all the heck over the place) or block the thread for human-noticeable chunks of time (also very gross of course!).
- eastbound 3y agoAnd it’s LTS! When is the book and the certification exam coming out, does anyone know?
- smallerfish 3y agoCan you explain why you're excited about with virtual threads? I get that they improve throughput in extremely high pressure apps, but the JVM's current threading isn't exactly a slouch. Java's used in HFT shops, and more generally in fintech where performance matters.
- maxpert 3y agoFinally virtual threads I can use in production with generational ZGC! I've been using Kotlin coroutines for a while now, and want to see how that evolves with JVM now supporting virtual threads out of box.
- palata 3y agoI'm curious: will virtual threads make coroutines "better" (like, more efficient), or will they just enable different ways of doing concurrency?
- svieira 3y agoBoth - Kotlin's coroutines are a runtime for green threading. The implementation of that runtime could use Java's green threads for many things and where the developer UX or guarantees aren't there, fall back on other primitives. But users of Kotlin could also just use Java's new virtual threads if they don't need anything fancy from Kotlin's coroutine runtime. You probably wouldn't want to _mix_ these threading approaches in a single codebase unless Kotlin's coroutines become a literal "dev UX facade" because otherwise things like ThreadLocals (and whatever Kotlin provides as an alternative) can get out of sync.
- _ZeD_ 3y agojava async stuff is not colored :)
- bad_user 3y agoTrue. Although, I find that in practice Kotlin's coloring is quite pleasant to use due to the calling conventions and the tooling.
- wiseowise 3y agoColor is a feature in Kotlin: https://elizarov.medium.com/how-do-you-color-your-functions-a6bb423d936d https://elizarov.medium.com/how-do-you-color-your-functions-...
- alex_suzuki 3y agoIncludes JEP 449 (deprecation of Windows 32-Bit builds) https://openjdk.org/jeps/449 https://openjdk.org/jeps/449 I wonder how long those builds will remain available.
- alexvitkov 3y agoAs much as I want to clown a little on the language for taking so long to do string templates, congratulations on getting virtual threads shipped, I can't imagine the effort that must've took to implement into something as hairy and complex as the JVM!
- jjtheblunt 3y agoThe JVM originally had green threads, super super similar.
- kaba0 3y agoAnd we had electric cars before internal combustion engines.. they are not at all the same, and not even my analogy gives enough credit to loom.
- roschdal 3y agoHow is this new release better than Java 1.4.2? What can a server running Java 21 do that wasn't possible in Java 1.4.2? It's an opportunity to reflect on the material differences in this new release.
- freedomben 3y agoIs this a(n attempted) troll or an honest question? There's a mountain of new libraries and language features since then ...
- deleted 3y ago[deleted]
- karmakaze 3y agoComparing it to Java 1.5 is a better baseline since before that, Java didn't have a defined memory model so was an implementation-defined 'wild west'. Also, we can then skip the basic has/not-has generics.
- paulddraper 3y ago> What can a server running Java 21 do that wasn't possible in Java 1.4.2? Virtual threads
- kaba0 3y agoAt that point, why develop anything? The first Turing-complete processor is enough for everything anyone will ever want.
- paulddraper 3y agoAs long as it has 640KB of memory.
- m8s 3y agoAre there modern learning resources available for Java?
- riffic 3y agoleetcode
- hickelpickle 3y agoBest learning resource imo is https://www.onjava8.com/ https://www.onjava8.com/ (it covers up to java 17) Bruce Eckel is fairly well known for his original Thinking in java/c++ books, and I find his style of writing great. He has a knack explaining topics in an easily digestible thorough way, while not being completely dry. Its a 1200 page book, and can double as a reference, but actually explains the when, how and why in thoughtful writing enough to double as a great book for learning and a reference when needed. I knew a lot about java and learned a lot of little things about topics I already knew, and it breaks down each piece of the language so you can easily gloss over things you already may know from other from other languages.
- lambda_garden 3y agoI have a genuine question about Loom / virtual threads / etc. In languages with async-await syntax, I like that it is explicit what is sync and what is async. I also like how the "bind" points within an async expression make it clear where the syncronization happens. It seems to me that Java 21 makes all of this implicit, which is a step backward in this respect. Similar to how types enforce valid usage (a foundational idea in Java), I feel that an Async<T> should not be implicitly a T. Are people concerned about this at all? Have the Java designers addressed this?
- djur 3y agoWhy do you like that? What problems has it helped you solve or avoid?
- lolinder 3y agoNot OP, but I agree with them. Here's my take: If you design your software right, you can use async/await similarly to IO in Haskell—functions that are not async are fast and unlikely to fail, while functions that are async are potentially slow and likely to throw exceptions. This partition can help you reason about and structure your code as you're writing it for solid error handling and minimal duplicate I/O.
- hocuspocus 3y agoYes but Java is not Haskell. If you want a monadic IO on the JVM, Scala offers two ecosystems with extremely capable effect systems, providing highly performant runtimes and good (but not perfect) ergonomics. I've always found async/await bolted on older, mostly imperative OO languages with exceptions to be pretty disappointing. Even modern designs on languages with proper error handling like Rust get their fair share of criticism. I get that virtual threads will probably introduce surprising bugs and performance issues in some corner cases. But it also removes a whole lot of craziness in the Java ecosystem, namely reactive programming.
- deleted 3y ago
- 5e92cb50239222b 3y agoSome options for those who prefer to avoid the Oracle minefield: https://adoptium.net https://adoptium.net https://aws.amazon.com/corretto https://aws.amazon.com/corretto https://www.azul.com/downloads https://www.azul.com/downloads https://bell-sw.com/pages/downloads https://bell-sw.com/pages/downloads Sadly, no-one has managed to package it yet, but we should get something in the next couple of days. Since 21 is an "LTS" release, major Linux distributions will provide a runtime pretty soon. Ubuntu backports them to old releases too.
- geodel 3y agoWhat is that minefield? How is avoided by repackagers? Do they take legal liability of Oracle lawsuits related to Java?
- belter 3y ago"Oracle(Java) is knocking at my company's door and they want money." - https://www.reddit.com/r/sysadmin/comments/165kzxg/oraclejava_is_knocking_at_my_companys_door_and/ https://www.reddit.com/r/sysadmin/comments/165kzxg/oraclejav...
- kaba0 3y ago“I downloaded Photoshop and now adobe asks for its price”
- freeone3000 3y agoThe JDK is GPLv2, which means it can be legally redistributed without charge. Oracle puts their JDK release under a different license. Microsoft distributes the binaries under the GPL. It’s the same code going into the binary, but different license terms.
- kaba0 3y agoOracle provides their builds for free, given you use their latest LTS release. But that’s apples to oranges comparison - that is an actual support release, meant for big enterprises that wants to point their fingers at someone on Christmas eve.
- consoomer 3y agoWhere's Java primarily used these days?
- jlnho 3y agoEnterprise ETL/CRUD stuff and (some) native Android applications.
- yankput 3y agoAndroid doesn’t follow the Oracle Java though, right. So all these new features are just not there, right
- jlnho 3y agoNot yet, I believe they currently support everything (or nearly everything) up to Java 11.
- bad_user 3y agoThe compile-time features end up being supported. The runtime features (e.g., invokeDynamic) less so. OTOH, Android would benefit from virtual threads, too, which is one of the reasons they've jumped feet-first on the Kotlin train (and Kotlin's coroutines are pretty well designed).
- charcircuit 3y agoIt uses their compiler javac. Then the class files get compiled into dex files for androids runtime.
- belter 3y agoI think the question is more where is not...
- jlnho 3y agoThe world "primarily" is important here. Sure, you _can_ use Java for embedded and even real-time stuff. Some games are written in Java, etc. But no one would say that Java is the primary language of choice in such domains.
- martypitt 3y agoI can't wait to see if/how tools like Reactor and Kotlin Coroutines adapt with Virtual Threads, and if they extend the tooling, or provide a migration path. I've written a tonne of code on both Reactor and Coroutines, and would love something simpler, but dread the idea of migration.
- samus 3y agoIf you have working code that uses reactive frameworks, think twice about refactoring. Primarily , because it /works/. The reactive calls might also have some non-obvious semantics that could get lost if you don't carefully translate them to virtual threads.
- eddtests 3y agoAnyone know when homebrew installs will be released for JDK 21?
- yolo3000 3y agoIs there any good docs website for Java? These release notes have such a bad design, and it seems that if you want to learn more of what are the features you need to dig into the mailing lists.
- ulimn 3y agoI kind of like the inside java website for these kind of things: https://inside.java/2023/09/19/the-arrival-of-java-21/ https://inside.java/2023/09/19/the-arrival-of-java-21/
- mgomez 3y agohttps://docs.oracle.com/en/java/javase/ https://docs.oracle.com/en/java/javase/ If you're like me and more interested in language additions, each release entry has a "Language Updates" section (under "Language and Libraries") with example code/usage.
- jgon 3y agohttp://dev.java http://dev.java might be what you're looking for.
- shortrounddev2 3y agoWould be cool if oracle worked on their presentation a bit. Whenever MS releases new C# features they've got a blog post showing the features off and how they can be used. Oracle just kind of dumps a bunch of JEP links
- capableweb 3y agoMaybe this is a better link for you? https://jdk.java.net/21/release-notes https://jdk.java.net/21/release-notes Each feature links to a deeper dive into it.
- shortrounddev2 3y agoThat's the link I'm talking about. A website which looks like it's from 2002, linking to each JEP. No syntax highlighting, and paragraphs of text to read before really showing a compare/contrast. It's the kind of thing that was written by programmers and not by writers Compare to C# releases: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10 https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/cs... Most links take you to a section of the same page, with syntax highlighting and optional light/dark mode on the site. For some features, it doesn't explain the rationale behind the change, it just shows the before/after, which is really all I care about: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10#assignment-and-declaration-in-same-deconstruction https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/cs...
- capableweb 3y agoPersonally, all of what you wrote is a benefit when it comes to release notes. I don't want flashy GIFs, words written by non-programmers who don't actually understand what they are writing and I definitely don't want the marketing/web design part of a company to be involved in it. Simple, tell me what changes, where I can read more and that's it. It's the perfect release notes. But, as always, people like different things, as is apparent here :)
- 3y ago
- shortrounddev2 3y agoOracle managed to create one of the least ergonomic string interpolation syntaxes of any language I've ever seen. Using backslashes is truly a terrible move
- pjmlp 3y agoThey are just following that other famous language for developing mobile apps. While I don't like it, all other alternatives were kind of taken by libraries. And who knows, since it is preview, it might still change.
- kaba0 3y agoMay I introduce to Swift? They even decided on that without any backwards compatibility limitations. It really is not bad, does it really matter if it’s a $ or a \ ?
- shortrounddev2 3y agousing backslashes for anything other than escaping a characters (e.g: \" or \n) makes it a nightmare to try to coerce the compiler into understanding what you're trying to do if you combine escape characters and syntax in the same string
- kaba0 3y agoYou get a giant ass bracket after it. How is it not readable? “\{a}+\{b}=\{ a + b }\n” Do you also criticize this? “Price: $${price}”?
- shortrounddev2 3y agoTry, for example, generating a regular expression which features backslashes in it. You will get an unreadable mess and probably have to play with it for a while before java will even compile it
- 3y ago
- fnord77 3y agoI know java has fallen out of favor these days. I blame the ghastly complexity of j2ee and Spring, which can't seem to say no to any academic design pattern. Also Oracle But java is a peach for complex systems that need to scale both in terms of performance and in terms of number of people working on the system.
- anthony_d 3y agoI wish there was a good way to separate Java from the hell that is Spring. Technically I don’t have any issues, but the culture that goes with Spring destroys all software and my will to live.
- peheje 3y agoCan you elaborate
- frant-hartm 3y agoSpring and Android are 2 things which keep Java relevant. Sure there are projects using neither, but majority of Java code written nowadays is.
- za3faran 3y agoOnly in the hipster blogosphere. In the real world, Java is quite strong.
- foolfoolz 3y agosurprised to see all the comments about virtual threads. the real best feature of this release is record pattern matching in switch. this is a huge syntax improvement
- YeBanKo 3y agoOh no. Without record pattern matching you have to have few extra variables declared in scope. Easy with modern IDE. Async code with either a spaghetti of CompletableFutures or reactive style is a nightmare. But I can achieve the same throughput with a “virtual thread per request” style as with reactive, it’s a game changer.
- aoetalks 3y agoVirtual threads, generational GC, manual memory management, all things .NET has had for ages. Too bad it can’t shake the “MS tech is boring” reputation
- _old_dude_ 3y agoIt's not generational GC, it's generational ZGC. ZGC is a concurrent GC, both the marking phase and the evacuation phase are done concurrently with the program running. A generational ZGC is a generational concurrent GC. MS does not have such kind of tech.
- dividedbyzero 3y agoAren't you quite limited when targeting or developing on non-Windows platforms with .NET?
- marginalia_nu 3y agoWell, yeah, that's been Java's explicit philosophy for decades. Let other languages evaluate cool new features first, then learn from their mistakes and promise backward compatibility "forever".
- cornstalks 3y agoHow do people deal with old clients? The Android app I (partially) work on can't even use JDK 8 (I learned this when trying to use Double.hash() to hash a double). Coming from C++, where I can use C++20 and still deploy to ancient devices, I'm seriously baffled how people work with Java. Is there any way to use new JDK features in an Android app that also has to deploy to Android SDK 21 (i.e. Android 5.0 from 2014!)?
- kaba0 3y agoAndroid doesn’t use proper Java, it runs their own bastard child of it. You can sometimes get away with byte code desugaring of more modern features sometimes, and it has been getting better recently, but it is far from ideal.
- jillesvangurp 3y agoIf you develop for Android you likely use either Kotlin or Flutter; either way there's very little in this Java release that matters or should excite you. Kotlin has already had most of the features that Java has been adding over the last few releases in some form or another and most Android users use those a lot. So, from that point of view there are maybe a few things that Kotlin could do nicer but nothing world shocking.
- cornstalks 3y agoThe things I'm most interested in are JNI-related. Project Panama[1] will bring a ton of improvements. These aren't stable in JDK 21 but I'm anticipating their stability in the near(ish) future (JDK 22? 23?). I'd like to experiment with some of the preview APIs in JDK 21 but given I can't even use JDK 8 I'm wondering if I'm just SOL and if I should abandon all hope for me using things from Project Panama. [1]: https://openjdk.org/projects/panama/ https://openjdk.org/projects/panama/
- paulddraper 3y agoCross-compilation is possible. (See javac -target.) I'm not sure what the current matrix of support for this is.
- aoetalks 3y agoDuplicate of: https://news.ycombinator.com/item?id=37569573 https://news.ycombinator.com/item?id=37569573
- dang 3y agoThanks! It's probably better to merge the comments hither since this URL is more informative.
- mike_hearn 3y agoOne aspect of virtual threads that has gone somewhat unappreciated so far is that if you (ab)use some internal APIs you can probably implement the testing technique used by FoundationDB. For those who don't know, FoundationDB is a horizontally scalable transactional (KV) database used by Apple for their cloud services. It's famous primarily for its testing approach in which they can run the entire set of microservices in a simulator that can both inject faults, but also completely control the scheduling of work. In this way they make the system entirely deterministic, and can then pseudo-randomize simulations to uncover race conditions and the like. To do this they created a custom DSL on top of C++ called Flow which is compiled to coroutines. https://www.youtube.com/watch?v=4fFDFbi3toc https://www.youtube.com/watch?v=4fFDFbi3toc Flow and what it enables is considered (by them at least) to be a key competitive advantage over other database engines. With Loom the JVM now happens to support the very same thing, just not officially. That's because the JVM makes file and network IO fully "pluggable", virtual threads can be supplied with a custom scheduler, and classloaders can be used to run multiple programs within the same JVM (with some caveats). So if you wanted to make a deterministic simulation of your microservice based system then you could do that now. The above would be a rather advanced project for intrepid developers only, but it'd be interesting to see someone explore that at some point.
- slantedview 3y agoInteresting idea. Are there any implementations of this sort of thing in the wild?
- deleted 3y ago[deleted]
- papercrane 3y agoIt was explored a bit in a blog article with some sample code. One big issue with this approach right now is that the scheduler is not officially user replaceable. It's possible using reflection to do so though, at least is was in 2022, the internal code may have changed since then. There's been some indication from the OpenJDK team that this might be an officially supported feature in the future. Blog article: https://jbaker.io/2022/05/09/project-loom-for-distributed-systems/ https://jbaker.io/2022/05/09/project-loom-for-distributed-sy... HN discussion: https://news.ycombinator.com/item?id=31314006 https://news.ycombinator.com/item?id=31314006
- jjtheblunt 3y agoCan the JVM represent a uint32 yet or a uint64? If so, I overlooked it.
- capableweb 3y agoLong should be able to do the trick for you? > Long l1 = Long.parseUnsignedLong("17916881237904312345"); Or, just use BigInteger
- wavemode 3y agoJava not having unsigned types is a feature IMO.
- jjtheblunt 3y agoWhy has this been helpful for your uses? (I ask from someone who has been away from Java since 2001 for the most part, in Swift and Rust and of course C.)
- wavemode 3y agoMost uses of unsigned are a code smell. People think unsigned means that something can't go negative. This isn't really true though. It CAN go negative, and then it silently wraps around and you then lose the ability to detect that it went negative.
- reaktivo 3y agoIf me as someone experienced with the JavaScript ecosystem would like to get started learning latest Java, where should I start? Interested in building web applications.
- onetom 3y agoI think these days Clojure is a nicer way to easy into the Java ecosystem, because you can explore existing Java libraries interactively. Here is a nice demonstration of what can you expect, if you want to build a web app: https://youtu.be/LcpbBth7FaQ?si=PCZijF-JRmp0xxbz https://youtu.be/LcpbBth7FaQ?si=PCZijF-JRmp0xxbz If you add https://htmx.org/ https://htmx.org/ into the mix, then you can build highly interactive applications, with a lot less complexity compared to building a purely data API consumed by some JavaScript frontend framework (React/Svelte/SolidJS and even ClojureScript) Also, if you learn Clojure, you get a lot more benefits. Shorter programs, which are easier to reason about and hence easier to maintain, etc.
- derkoe 3y agoOne of the most common web frameworks used is Spring Boot - here is their quickstart: https://spring.io/quickstart https://spring.io/quickstart Newer alternatives are: https://micronaut.io/ https://micronaut.io/ and https://quarkus.io/ https://quarkus.io/ If you want to have something really simple look at Javalin: https://javalin.io/ https://javalin.io/
- dang 3y agoRelated: Java 21 makes me like Java again - https://news.ycombinator.com/item?id=37538333 https://news.ycombinator.com/item?id=37538333 - Sept 2023 (728 comments) Java 21: First Release Candidate - https://news.ycombinator.com/item?id=37126530 https://news.ycombinator.com/item?id=37126530 - Aug 2023 (107 comments) Java 21: What’s New? - https://news.ycombinator.com/item?id=37067491 https://news.ycombinator.com/item?id=37067491 - Aug 2023 (256 comments) Java 21: No more public static void main - https://news.ycombinator.com/item?id=36189923 https://news.ycombinator.com/item?id=36189923 - June 2023 (77 comments) JEP 430: String Templates (Preview) Proposed to Target Java 21 - https://news.ycombinator.com/item?id=35012862 https://news.ycombinator.com/item?id=35012862 - March 2023 (237 comments)
- mdaniel 3y agoand, of course, the unholy number of pseudo-dupes: https://hn.algolia.com/?dateRange=last24h&page=0&prefix=true&query=java%2021&sort=byPopularity&type=story https://hn.algolia.com/?dateRange=last24h&page=0&prefix=true... https://hn.algolia.com/?dateRange=last24h&page=0&prefix=true&query=jdk%2021&sort=byPopularity&type=story https://hn.algolia.com/?dateRange=last24h&page=0&prefix=true... as everyone picks their favorite perspective on the launch
- jpgvm 3y agoReally great release, Virtual Threads have been eagerly anticipated. Now it's just the waiting game for Valhalla and Panama to land which will address the last of the things that make me sometimes pull my hair out.
- YeBanKo 3y agoCan anyone recommend a good book queueing theory math that goes beyond Little’s? Preferably with exercises.