Live data from Hacker News

Java 21 makes me like Java again

wscp.dev

481–490 of 777 posts

Re: Java 21 makes me like Java again

#481

Earlier quoted context omitted.

Go's major selling point to me is that you can ship one binary, nothing beats that. Python, Node, Java all have to pre-install lots of dependencies before you can use them, fine for developers, not so great if you want to distribute software for people who are not software savvy, who typically just wants to download one file, install and start using it. c and c++ can also do one executable, but, it is not as portable…

You mentioned "distribute software" but did not consider Electron for Node. You can make an Electron app with JavaScript and ship the binary (or installer) on any platform. It's not a single executable file, but the user experience is the same. I don't think there's an equivalent in Go that allows you build a desktop app like that (with frontend and backend both written in Go)?

You can do that with Java too. The JDK has jpackage, but if you want something better than I'm willing to sell that to you (or give it for free, if you're open source):

https://conveyor.hydraulic.dev/

It can be used to ship servers, we use it that way for our own servers. It sets up systemd so you don't need to use Docker. But where it shines is desktop apps.

Windows users get a little 400kb EXE that installs/updates your app and then immediately starts it without user interaction required, so it's effectively a single EXE. Mac users get a bundle. Linux, well, Linux users get a deb that sets up the app+its apt repo, or a tarball. Maybe in future a FlatPak or Snap or something else.

It knows how to bundle and minimize a JDK along with your app as part of the release process. Works great for desktop apps.

It's for Electron too, same deal, easier than Forge in my humble and very biased opinion.

Re: Java 21 makes me like Java again

#482
post #329

Earlier quoted context omitted.

Go almost instant build time is a huge productivity boost when compared to Java. You get both the solidity of a typed language, and the development speed of interpreted languages (py, js).

Java's build times are very fast. Java's build tools are anything but. And I'm surprised no one is doing anything about it.

Gradle, when the daemon is runnning is very fast, people just often fck up their build scripts to include config-time run functionality, which is just all around a stupid thing to do.

It only ever runs tasks that actually have to be run, has integration with javac, can work in parallel, and even has cross-company build caches if needed.

Also don't forget that Java can do hot reloads with the debugger, or with tools like JRebel. Certain frameworks support it 100% and it will be much much faster than whatever go does.

Re: Java 21 makes me like Java again

#483

The biggest feature in Java 21 is the release of Virtual Threads: https://openjdk.org/jeps/444 For some reason, this is missing from the article. If there was any feature that would sway existing Golang developers to switch to Java, it would be this. It would perhaps also convince the haters of the reactive-style concurrency patterns.

I wonder: are virtual thread at the JVM level? If so, would Kotlin (and other JVM languages) be able to leverage virtual threads to improve (e.g. produce more optimal JVM bytecode) for their async functionality?

Re: Java 21 makes me like Java again

#484
post #429

Earlier quoted context omitted.

Why async/await is not a good thing? What makes green threads better? Do you know the difference, the issues async/await addresses that green threads simply do not?

Read David Fowler's guidelines.

Do you have link to any specific article of his (on virtual threads vs async)?

Re: Java 21 makes me like Java again

#485

The "Sealed classes" feature, as described here, just feels all wrong to me. They are saying that if you have a (normal) interface, anyone can create a new class implementing it. So if you do if (x instanceof Foo) { ... } else if (x instanceof Bar) { ... } ... then your code will break at runtime if someone adds a new class, as that code won't expect it. So the article is saying the solution is to use the new "sealed…

It doesn't always make sense to allow extending -- String is `final` for a reason (and one might even argue that final should be the default, and one should explicitly mark with `open` classes that can be subclassed).

The stereotypical FP example for sum types are a List -- there you only have an Element(T head, List tail) and a Nil(). There is no point extending it, it would, in fact, result in incorrect code in conjunction with all the functions that operate on Lists.

Also, the Visitor pattern, which is analogous to pattern matching is very verbose and depends on a hack with the usual method dispatch semantics of Java. I do think that pattern matching is several times more readable here.

Re: Java 21 makes me like Java again

#486
post #360

Earlier quoted context omitted.

> the sane members of the Java community have long since moved on from Java, and they're not coming back We wish! We're stuck in the Java job market, reading Java praise pieces like this... Oh boy! Java's getting structs?

How long until we get continuations in Java? Maybe another 10y? How long until we get TCO? Lets say 20y? And in the end it will still not feel clean or as neat as other languages, that had this stuff for multiple decades.

None of those are a necessity, and they can be easily implemented in an additional layer (e.g. annotation processor if you really wanted to).

Re: Java 21 makes me like Java again

#487

Earlier quoted context omitted.

Java 21 has me anticipating the next JRuby release because of Virtual Threads. Charles Nutter gave a talk about JRuby in August where he showed a demo of the impact on Ruby fibers and it’s pretty significant. There’s a lot that I really like about the JVM and it’s tooling, I just don’t like writing Java code anymore. JRuby kinda gives the best of both worlds. Here’s the talk. Virtual thread demo is around the 45 minu…

I loved this. Is there any post comparing Ruby performance with JRuby?

There are lots. Usually these days, also comparing with TruffleRuby, which also runs on the JVM.

This one is a couple years old now but you get the idea:

https://eregon.me/blog/2022/01/06/benchmarking-cruby-mjit-yj...

I don't know where to find more up to date benchmarks.

Re: Java 21 makes me like Java again

#488
post #202

Earlier quoted context omitted.

Well when Sun imploded and Oracle stepped in, Java stopped getting regular releases for 10 years. Java versions literally came out every 2 years before Oracle happened. So that’s why they’re 10 years behind. But now they come out like 2+ times a year so they’re on track making major progress. Also the null thing hasn’t been an issue for over 10 years. Just use null annotations and both your static checker and your ID…

> Also the null thing hasn’t been an issue for over 10 years. I don't think I've ever seen a Java codebase that doesn't experience NPEs in prod, and that includes modern greenfield ones that make use of all the tools to combat it. > Just use null annotations and both your static checker and your IDE will catch every NPE. Yeah, or just catch it in code review, or just xyz... Or, just switch to a compiler that doesn't…

> I don't think I've ever seen a Java codebase that doesn't experience NPEs in prod

Frankly, the last NPE I saw in production was many many years ago.

Re: Java 21 makes me like Java again

#489
post #480

Earlier quoted context omitted.

> Java (and preferably Kotlin) are a lot more serious about making sure your code is robust before it compiles. You are making great points for Rust, Ocaml and Haskell.

There isn't all that many plus in their type systems that is not expressible in Java. OCaml and Haskell has Monads, sure. There is Scala for that on the JVM.

> There isn't all that many plus in their type systems that is not expressible in Java.

Thanks to Turing, anything that is Turing-complete can duplicate any other thing that is Turing-complete. So, yes, you can do all of Haskell's types in Java. That is not a flex.

The flex is doing them in a non-horrific way.

Re: Java 21 makes me like Java again

#490

The biggest feature in Java 21 is the release of Virtual Threads: https://openjdk.org/jeps/444 For some reason, this is missing from the article. If there was any feature that would sway existing Golang developers to switch to Java, it would be this. It would perhaps also convince the haters of the reactive-style concurrency patterns.

`Executor.newVirtualThreadPerTaskExecutor` versus `go` really gets to the heart of why I think that Go developers aren't going to be switching. edit: Sorry, it's actually: try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { executor.submit(...) ) instead of `go`

If you want to use that with more concise syntax, there is Kotlin for that. In which case abstracting that is one line of code tucked away in a utility file:

    fun  go(body: ExecutorService.() -> T): T =
        Executors
            .newVirtualThreadPerTaskExecutor()
            .use(body)
Now you can write:

    val result = go {
       val result1 = submit { slowOp() }
       val result2 = submit { blockingOp() }
       result1.get() + result2.get()
    }
or words to that effect. You can also reduce it a lot in Java too, as mentioned by another commenter.

    class Shortcuts {
        static  R go(Function task) throws RuntimeException {
            try (....) { return task.apply(service) }
        }
    }
and then you can write:

    var result = go(service -> {
        var result1 = service.submit(() -> slowOp());
        var result2 = service.submit(() -> blockingOp());
        result1.get() + result2.get();
    });
using static imports.

Now if you're making a cultural point then sure, Java APIs tend to be named quite explicitly. It has advantages when searching or auto-completing, and it's easy to wrap with aliases if you want to abstract a boilerplate pattern away.

Post reply on HN