Live data from Hacker News

Java 22 Released

mail.openjdk.org

61–70 of 178 posts

Re: Java 22 Released

#62
post #51

Maybe my favorite feature in this release: https://openjdk.org/jeps/463 Finally solves the inscrutable Hello World program! Yes, it's just ergonomics for early beginners. But could be the difference in whether or not someone new to programming sticks with Java or not.

They almost caught up with C#, which ditched requisite class declarations years ago. Although C# went one step further and allowed top-level code outside of methods, so that hello world is now: Console.WriteLine("Hello, world!")

You can write write code outside of methods in a Java class, called an initializer block:

  class MyClass {
    {
      System.out.println("Hello World!");
    }
  }
This will run when an object of the class is instantiated. So not useful for the case in question (you could get rid of the class declaration but would presumably still need a main method).

(It's also pretty poor style, but occasionally useful in a pinch, like when instantiating an anonymous inner class, which has no constructors that take arguments)

Re: Java 22 Released

#63
post #20

Earlier quoted context omitted.

I started to tinker with this new API last week. I definitely think it's a lot better than needing to self compile a lot of the bindings yourself which will certainly bring more from the community into the feature than were here before. That said, you really need to write a bunch of boiler-plate to implement useful things in java-like paradigms in the library today. Just as an example, I wrote up a sane windows _getc…

I've been quite keen on the new FFI too - apologies if this is old news, but have you tried the [0] jextract stuff for some of the boilerplate gubbins? [0]: https://github.com/openjdk/jextract

No! Thanks for the callout! That would certainly help on my path. My main goal was to insulate calls to avoid overly complicated reference counting when integrating large native surfaces into as Java program, but certainly an important aspect is getting the function signatures to target in the first place. I threw something bad together to work sort of like this (testing using proton), but I'm more than happy to bin it for something that just-works.

Re: Java 22 Released

#64

It isn't a "Sexy" PL change, but a full foreign function interface will be a huge change. In my experience, relying on the old java JNI based libraries seems to be one of the biggest things that break in upgrades. So I am hoping this will reduce the maintenance burden of Java.

Boring changes like these are what keeps Java interesting. New and shiny syntax sugar becomes stale real quick.

As a modern language Java is still quite feature deficient. But you can use compiler plugins like the manifold project[1] to level up.

1. https://github.com/manifold-systems/manifold

Re: Java 22 Released

#65

Maybe my favorite feature in this release: https://openjdk.org/jeps/463 Finally solves the inscrutable Hello World program! Yes, it's just ergonomics for early beginners. But could be the difference in whether or not someone new to programming sticks with Java or not.

Maybe in another ten years they'll remove System.out.println and allow for a simple println to be used.

Or maybe we'll all move to Kotlin by then.

Re: Java 22 Released

#66
post #46

It's kind of startling to see how many places still use Java 8, estimated at ~1/3 of projects according to a survey i just googled. And something like half that still use java 11.

I'm dragging my new company's codebases from 8 to 17 from soup to nuts. It's not always just about the language update, but all the old legacy crust that accumulated since java 8 that prevented anyone else to do it. My PRs are terrible and necessary.

Re: Java 22 Released

#67
post #55

Earlier quoted context omitted.

The FFI is also an artifact of CLR type system and the ability of have proper stack value based types.

Not just value types, but also: 1. Pointers to the same (and not just references to objects). 2. Unions (via explicit-layout structs) 3. Function pointers. 4. C-style varargs. To be fair, not all of these have been exposed in C# historically even though CLR had them all along. Most notably, unmanaged function pointers took over 20 years. And since most people look at CLR through the prism of C#, they aren't necessari…

Honorable but important mentions:

5. Stackalloc (C alloca), fixed buffers in structs and inline arrays

6. ref T and Span, which act just like &mut T and &mut [T] in Rust (with the same syntax). They are used in both advanced and most basic APIs alike to provide zero-cost wrapping and/or slicing of arbitrary memory (managed heap, stack, NativeMemory.Alloc'd)

e.g. You can receive byte* and length from FFI and construct a (ReadOnly)Span from them. That span then can be passed to almost every method that used to work with arrays only during .NET Framework days.

Re: Java 22 Released

#68
post #56
post #46

It's kind of startling to see how many places still use Java 8, estimated at ~1/3 of projects according to a survey i just googled. And something like half that still use java 11.

8 reached EOL in the last year or two. I think 11 is still under LTS. Part of the problem is the changes made between 8 and 17 could be incredibly disruptive depending on your libraries. If they had stuck to not using sun.* stuff you were pretty safe, but a few very popular things did. Then somewhere in there a lot of the common server stuff moved from javax.* over to jakarta.*. Both were needed and very good, but co…

> 8 reached EOL in the last year or two

Java 8 is still under Extended Support until 2030 (and indefinite sustaining support). Java 11 left Premier Support September 2023.

"Java SE 8 has gone through the End of Public Updates process for legacy releases. Oracle will continue to provide free public updates and auto updates of Java SE 8 indefinitely for Personal, Development and other Users via java.com".

https://www.oracle.com/java/technologies/java-se-support-roa...

Re: Java 22 Released

#69
post #46

It's kind of startling to see how many places still use Java 8, estimated at ~1/3 of projects according to a survey i just googled. And something like half that still use java 11.

Wait until you hear about COBOL still being used.

Snark aside, the problem with Java in the enterprise is that Oracle provides support for mind-bogglingly ancient versions (if you're willing to pay them). This disincentivizes companies from upgrading, ends up frustrating their developers, and has probably contributed to the negative reputation that Java has in some corner of the net.

I get that tracking the current version isn't feasible for most companies, especially if software isn't their core business. The Java folks do their best to make upgrades painless, but the longer you wait, the more painful it gets.

Re: Java 22 Released

#70

Maybe my favorite feature in this release: https://openjdk.org/jeps/463 Finally solves the inscrutable Hello World program! Yes, it's just ergonomics for early beginners. But could be the difference in whether or not someone new to programming sticks with Java or not.

My first Java programming course went over in detail about that piece of code and in a couple of hours taught me a lot of important Java concepts right away. Consider me not enthused about it.

Simple code like that kept pulling me back to the JSL 1.0 spec time and time again as my understanding deepened, much like the old singleton pattern debates of old.
Post reply on HN