11 ms·
All New Java Language Features Since Java 21
- rafram 1y ago[video]
- Almondsetat 1y agoIsn't there a textual version? Seems pretty inefficient to have a video that is basically a big list
- deleted 1y ago[deleted]
- jorrdang 1y agoCopied this from the video description: JEP 395: Records: https://openjdk.org/jeps/395 https://openjdk.org/jeps/395 JEP 440: Record Patterns: https://openjdk.org/jeps/440 https://openjdk.org/jeps/440 JEP 394: Pattern Matching for Instanceof: https://openjdk.org/jeps/394 https://openjdk.org/jeps/394 JEP 441: Pattern Matching for Switch: https://openjdk.org/jeps/441 https://openjdk.org/jeps/441 JEP 409: Sealed Classes: https://openjdk.org/jeps/409 https://openjdk.org/jeps/409 JEP 361: Switch Expressions: https://openjdk.org/jeps/361 https://openjdk.org/jeps/361 JEP 456: Unnamed Variables & Patterns: https://openjdk.org/jeps/456 https://openjdk.org/jeps/456 JEP 507: Primitive Types in Patterns, instanceof and switch (Third Preview): https://openjdk.org/jeps/507 https://openjdk.org/jeps/507 JEP 512: Compact Source Files and Instance Main Methods: https://openjdk.org/jeps/512 https://openjdk.org/jeps/512 JEP 458: Launch Multi-File Source-Code Programs: https://openjdk.org/jeps/458 https://openjdk.org/jeps/458 JEP 511: Module Import Declarations: https://openjdk.org/jeps/511 https://openjdk.org/jeps/511 JEP 502: Stable Values (Preview): https://openjdk.org/jeps/502 https://openjdk.org/jeps/502 JEP 513: Flexible Constructor Bodies: https://openjdk.org/jeps/513 https://openjdk.org/jeps/513
- p2detar 1y agoJEP 456: It’s crazy how glad I am to finally get rid of all those “ignored” vars in my code. > try (var ignored = CloseableThreadContext.put(…)) { to > try (var _ = CloseableThreadContext.put(…)) {
- tombert 1y agoI am a big functional programming geek. I am one of the few people on the planet who can honestly say I have been paid to write F#, Haskell, Clojure, and Erlang. I have spoken at FP conferences like six or seven times, and I have shit on Java for most of my career. And yet, my latest talk at Lambda Days basically boiled down to “Java 21 and later don’t actually suck anymore”, and I genuinely do mean that. Java 21 is actually fun to write, even for a grumpy FP advocate like me. Virtual threads make concurrency a lot simpler, and now that there’s proper records and ADTs (in the form of sealed interfaces), along with pattern matching, the language is actually pleasant to use. I haven’t dived into 25 yet, but I suspect I will like it as much or more than 21. The biggest issue, though, is that Java programmers won’t use the new features. It was like pulling teeth at my last job to get people to use stuff from Java 8 (e.g. the `var` keyword), and none of my coworkers even knew how to use NIO or BlockingQueues which I think predate agriculture. I mean, hell, I had explain what “fairness” was to engineers when using a ReentrantLock because someone “corrected” my code with `synchronized`. I don’t think Java makes people into bad programmers, but I do think it selection-biases for intellectually unambitious engineers. They learn exactly enough Java in college to pass their courses, and then get a job at a BigCo that doesn’t strictly require ever learning anything more than what they were taught in their “intro to data structures” course. I have met some extremely intelligent Java engineers who do have intellectual curiosity, so I am not saying it affects everyone, but I do think that they are the minority. Java 25 might add every feature to make my wildest dream come true but it won’t matter if I am not allowed to use it.
- Xenoamorphous 1y agoWhat do you think of “modern” Javascript to write FP?
- tombert 1y agoI haven’t touched much modern JS. I have done some TypeScript in the last few years but of course that’s a transpiled thing. I think TS isn’t too bad to write functional stuff though I have no idea if people actually enjoy reading my code.
- 1y ago
- vbezhenar 1y agoTLDR: Java 22: JEP 456: Unnamed Variables & Patterns Java 24: JEP 485: Stream Gatherers Java 25: JEP 511: Module Import Declarations Java 25: JEP 513: Flexible Constructor Bodies
- bullen 1y agoThe only new feature I might use since 1.8 (that only had NIO stability and GC improvements over 1.7) are the virtual threads without pinning in 24.
- ivanjermakov 1y agoWe extensively use vars, switch expressions, collector methods, String format methods, records, instanceof narrowing. Just from the top of my head.
- p2detar 1y agoSame here, plus sealed classes - a very powerful feature. What I actually haven’t used up to this point are VTs. I got a service that implements a job queue and it currently works flawlessly with scheduled executor pool. I’m reluctant to go with VTs before evaluating what implications that may have.
- bullen 1y agoI think VT's are only going to be interesting if you need 1000s of them doing tiny amount of small work often. For me I have been waiting for them for 20 years, as the blocking IO made MMO development impossible. In the meantime we got NIO in 1.4 that only became performant and stable around 1.7 so it's been a slow progress. I dug out my old blocking server code from back then and with a fresh coat of paint I'm ready to let the non pinned VT's rip and compare them to the NIO backend!
- p2detar 1y ago> For me I have been waiting for them for 20 years, as the blocking IO made MMO development impossible. I'm not into this area of work, but wouldn’t Netty have been helpful even before VTs became available?
- bullen 1y agoNetty has NIO... but back in 2000 there was no Netty. So 25 years back. JDK 1.4 with NIO came in 2002, Netty in 2004, but NIO only became usable live ~2010 with epoll and bugs got sorted end of 1.6! Also Netty is one of those middleware "pretend to help but really bloat" libs. I would sincerely recommend to avoid those as implementing on top of lower common denominators always is faster in the end after all the Netty bugs have been sorted.
- brap 1y agoAfter trying out many languages at many places, I reached the conclusion that Java, as weird as it may be, is my favorite language. There were times I hated it, but turns out I really just hated messy, over-engineered legacy code and working in a gray cubicle at aging MegaCorps. The language itself is quite beautiful when used properly and with modern features. It just really needs a makeover and better tools.
- leetcrew 1y agoit consistently works and has a huge ecosystem, but "beautiful" is never a word I would use to describe java. off the top of my head: * no type level concept of a const object (ie, you can have a const reference to a List, but never a reference to a const list). this makes const-ness an implementation detail of the class itself! so frustrating that List:add() can throw depending on the underlying class. * lack of tuples (and no, record doesn't count). this is just a syntactic sugar thing, but I really miss it from c++ and python. * var is far less powerful than c++ auto. in most cases, I actually prefer the syntax of c++, which is really saying something.
- joshdavham 1y ago> [Java] has a huge ecosystem But does it though? I've just taken a new job writing primarily Java whereas I was previously writing mainly python and typescript. One of the first things I've noticed is how dead Java's ecosystem (Maven central) seems in comparison to other ecosystems like PyPI, NPM or Cargo. (Also side note: I've published packages on each of these registries and the publishing process for Maven central is comically terrible! This has to be discouraging people from contributing to the ecosystem.)
- leetcrew 1y agoprobably depends on what kind of stuff you're working on. I mostly build web services and data pipelines on AWS, where java is still the best supported language (even if others have joined the list of officially recommended). java might not see the same brisk pace in library development as other languages, but it's also 30 years old. aside from core issues with the language that can't be papered over by 3P libs, what's missing?
- deknos 1y agoi would prefer it, if they improve and extend the java standard library and the tooling for libraries many people will tell you that the standard library is not as performant as it could be and does not have as many batteries as python and try managing your dependencies... that would be far more important than the next super duper feature IMHO.
- kasperni 1y ago> many people will tell you that the standard library is not as performant such as?
- mberning 1y agoI’ve worked in Java for over 20 years. Being the “lingua franca” of the enterprise is its biggest strength IMO, but it is also perplexing to me that it was able to do that in the first place. The language itself is not bad. The tooling around it is very good. But the codebases you encounter written in it, particularly in the enterprise, are often horrible.
- kasperni 1y ago> But the codebases you encounter written in it, particularly in the enterprise, are often horrible. Not sure they are worse than other languages?
- corytheboyd 1y agoHaving now experienced such Java codebases for the first time in my 15 year career… no, the Java code is much, much worse. Over engineered and otherwise poorly written Java code is SO much worse than other over engineered code I have worked with.
- eBombzor 1y agoHonestly for the limited projects I've had to work with... I can attest to that. It's the over engineered abstractions that get me. Traditional Java EE users use WAY too many abstractions and interfaces, it's absolutely horrible to debug.
- k0tan32 1y agoMind sharing why do you consider Java tooling to be good (and largely, what is good here)? The reason I ask is that I recently had to join a Java project at my company, and having a background in Node/Rust/Perl/Lua and some C++, I found the Java tooling to be extremely unsuitable for my taste. A simple example: there is no standard LSP server, and the amount of jumps required to have a working setup with FOSS tools and make it IDE-independent is just horrendous. In every other ecosystem I've worked with so far, it was pretty easy in the last 5 years: if you don't like IDEs, you can keep using your vim/emacs/helix or whatever and just embed a plugin or two, with LSP integrated -- and you're ready to go. Java world felt complete the opposite, like you had to use/buy some commercial tools to start doing something.
- jeroenhd 1y agoThe explanation on why Java lets you use unnamed variables to prevent accidental use during deconstruction, but those unusuable variables still getting initialized by calling accessors, is a perfect example why I dislike the way Java implements improvements. Every single, logical step that led to this hidden performance problem makes complete sense, because every improvement had to be its own tiny, contained improvement, but the end result is that `case Foo(int _, String _, User _, int age)` will still call three getters _just in case_ you're abusing the language to add side effects to accessors. Perhaps even worse is the explanation that follows: if you don't mess up your accessors, the JVM _may_ decide to not call those accessors at runtime. So now the language itself has this weird performance impact to maintain backwards compatibility, but at runtime that backwards compatibility _may_ not exist and provide you with a performance improvement instead, negating the whole reason why backwards compatibility was added in the first place. I like the improvements to Java, don't get me wrong. It's no longer the JDK 1.7 language poor enterprise programmers are stuck with. But if the Java people had come together and worked this out as one single feature, rather than five different ones, we wouldn't have needed to remember edge cases/a code analysis tool to remind us that using this intuitive language feature _may_ actually has a 3x performance impact depending on the mood the JVM is in today.
- deleted 1y ago[deleted]
- eweise 1y agoJava is becoming a poorly implemented Scala.
- vips7L 1y agoScala is a dead and complex language.
- eweise 1y agoScala definitely had some missteps but its much nicer to program in than Java and simpler as well. I mainly program in Go these days but I could imagine explaining the benefits of Scala over Go to my coworkers. It would be embarrassing trying to do the same with Java however.
- vips7L 1y agoI don’t think anyone I know would classify Scala as simpler. In my opinion Java is a much better language than Go. I can’t imagine anyone liking Scala would prefer it over Java.
- truth_seeker 1y agoany reasons to use Java over Typescript, Go or Rust for server side programming?
- akkad33 1y agoSpring is very capable and has lots of things built-in