Live data from Hacker News

All New Java Language Features Since Java 21

inside.java

101–110 of 130 posts

Re: All New Java Language Features Since Java 21

#101
post #67

Earlier quoted context omitted.

> 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 think that's a fair comment, but also there's this perspectiv…

Sure, I am not claiming that you have to use every new feature every day 100% of the time. Obviously there are cases where you can’t upgrade for legal or compliance or “customer is just being difficult” reasons. A lot of Java jobs aren’t that though, especially internal applications. A lot of places are running Java 17 or Java 21 on all their servers, literally have no plans to ever support anything lower, but the en…

I think it has a lot to do with work culture. Many tend to mimic what others are doing in order to not stick out.

At my previous job some were able to change that by consistently using "modern" features of Java. It inspired others to change and eventually we ended up with a good code base.

Be the one to start the change by implementing new features using good code. This will give others "permission" to do the same. Also try to give soft suggestions in code reviews or pair programming of simpler ways to do it (don't push too hard)

At my current job all of us were eager to try the latest features from the start, so we never had to convince new hires.

Re: All New Java Language Features Since Java 21

#102
post #4

I 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…

Programming language is a tool. Java developers value stability and ease of understanding for the code. I've seen the nice features you complain that don't get used, reality is that nobody wants to waste time knowing them unless they are intuitive to use. Especially when are forcing to use newer JDKs. There is no value in solving a challenge in a way that only you understand or make others lose time trying to underst…

> why would we ever want in Java to hold a variable that you can't read immediately what is the type

I can use my IDE to see the type if necessary.

> Everything that came after isn't really memorable nor helpful,

There are several improvements that are very helpful

One example is how multi line strings help me to read more clearly without the unnecessary string concatenations:

   var sql = """
             SELECT foo
             FROM bar
             WHERE last_updated > :lastUpdated
             """;
Another example is how switch statements have improved code readability, at least from my personal subjective viewpoint.

   String dayName = switch (day) {
      case 1 -> "Monday";
      case 2 -> "Tuesday";
      case 3, 4, 5 -> "Other day";
      default -> "Weekend";
   };

Re: All New Java Language Features Since Java 21

#103
post #99
post #72

Earlier quoted context omitted.

It’s amazing that Java has access to really great, high performing web toolkits like Vert.x and even Play, and yet the entire enterprise Java world has converged on Jakarta and Spring. I don’t like Spring but in my mind there is a special place in hell for Jakarta/JavaEE.

What’s wrong with Jakarta? (Genuinely curious)

[dead]

Re: All New Java Language Features Since Java 21

#104
post #90

Earlier quoted context omitted.

Tooling goes way beyond the editor/IDE. Eclipse is a very good free option. As is IntelliJ CE. I personally have the all products pack and use the ultimate version. Beyond the IDE you also have to consider the build tools, package management, debuggers, profilers, static analysis tools, etc. It’s honestly too much for an HN comment. But as an example, if I do open one of these awful projects at work and it uses gradl…

Thanks for sharing your experience. It's a fair note about tooling in general, I started with the code editing because it's the first thing before you can taste and judge the rest. I think my frustration comes from the fact that in most other ecosystem I can use the tools I like, but in Java I have to use things like Intellij. Intellij CE may be open source, but it is entirely owned by a private business whose primar…

There are several open source tools for Java (Eclipse, Visual Studio plugins, Netbeans and others).

The reason I don't use them is not because they are bad, but because IntelliJ is so much better.

I even use IntelliJ Ultimate for non Java code like React, even though Visual Studio Code seems to be de-facto standard for React developers and guides.

Re: All New Java Language Features Since Java 21

#105
post #95
post #71

Earlier quoted context omitted.

I generally hate when people use the “magic” excuse for not doing things. Most of these tools are open source and/or can be readily viewed in IntelliJ. It really isn’t hard…cmd+click on what you want to look at. If you’re an engineer you should be able to easily read the code to see what’s going on. Most of the time the “magic” can be understood in less than 30 minutes and then it’s not magic anymore.

I wouldn't dare say XML is better in this regard, but a good reason to be conservative with the use of annotations is exactly that cmd+clicking them doesn't easily lead to where the behavior is implemented.

Yeah, fair enough, though it's still not too hard to find where the behavior is implemented if you have access to the source code.

But you're right, cmd+clicking on the annotation just shows where the annotation is defined, not where the behavior is implemented.

Re: All New Java Language Features Since Java 21

#106
post #67

Earlier quoted context omitted.

Sure, I am not claiming that you have to use every new feature every day 100% of the time. Obviously there are cases where you can’t upgrade for legal or compliance or “customer is just being difficult” reasons. A lot of Java jobs aren’t that though, especially internal applications. A lot of places are running Java 17 or Java 21 on all their servers, literally have no plans to ever support anything lower, but the en…

I think it has a lot to do with work culture. Many tend to mimic what others are doing in order to not stick out. At my previous job some were able to change that by consistently using "modern" features of Java. It inspired others to change and eventually we ended up with a good code base. Be the one to start the change by implementing new features using good code. This will give others "permission" to do the same. A…

That's how it kind of was in my last job [1].

I know I came off as a bit negative, but in fairness to them, they did more or less continue working on what I was doing using the newer Java 21 features, and after I got a few pretty interesting changes merged in some of the more junior engineers started using them too; particularly I was able to successfully evangelize against the use of `synchronized` in most cases [2] and got at least some people using queues to synchronize between threads.

It honestly has gotten a fair bit easier for me since I've been doing this for awhile; at my last job I was the most experienced person on my direct team (including my manager) and one of the more experienced software people at the company, so I was able to throw my weight around a bit more and do stuff how I wanted. I tried not to be a complete jerk about it; there were plenty of times people would push back on what I was doing and I would think about it and agree that they were probably right, but I outwardly rejected arguments that seemed to be based on "I didn't learn this in university so it's wrong".

I have had other jobs (at much bigger companies) where they were not amenable to this. I would try and use new features and my PRs would be rejected as a result, usually with some vague wording of "this way is faster", which I later found out was (as far as I can tell) always a lie.

[1] It is not hard to find my job history but I politely ask you do not post it here.

[2] I'm sure someone here can give me a contrived example of where `synchronized` makes sense but if you need mutexes I think you're almost always better off with a ReadWriteLock or ReentrantLock.

Re: All New Java Language Features Since Java 21

#107
post #80
post #50

Earlier quoted context omitted.

Same 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.

I 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…

> 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?

Re: All New Java Language Features Since Java 21

#108
post #95
post #71

Earlier quoted context omitted.

I generally hate when people use the “magic” excuse for not doing things. Most of these tools are open source and/or can be readily viewed in IntelliJ. It really isn’t hard…cmd+click on what you want to look at. If you’re an engineer you should be able to easily read the code to see what’s going on. Most of the time the “magic” can be understood in less than 30 minutes and then it’s not magic anymore.

I wouldn't dare say XML is better in this regard, but a good reason to be conservative with the use of annotations is exactly that cmd+clicking them doesn't easily lead to where the behavior is implemented.

Sure. It is just another keyboard command in IDEA.

Re: All New Java Language Features Since Java 21

#109
post #35

Earlier quoted context omitted.

There is about zero difference in readability of your two statements, rending var not useful. And 'var accounts = calculateAccounts(something)' is literally less readable, because now you dont see what exactly accounts is. Var statement speed up writing, then are either irrelevant or gets rewritten to types for better readability.

I agree, and I'm not sure how something like 'var accounts = calculateAccounts(something)' can be thought of as better in a code review setting. I suspect using "var" or equivalent will be considered a problem by most companies within the next few years.

There’s nuance in programming. Both of these statements can be true. Var reduces boiler plate when you’re duplicating information in both the lvalue and rvalue.

I’m in agreement that when the information isn’t in the rvalue that you shouldn’t use var.

Re: All New Java Language Features Since Java 21

#110
post #86
post #83

Earlier quoted context omitted.

> The language itself is quite beautiful when used properly and with modern features. I respect your opinion but I wouldn't call Java beautiful (of course it depends on your definition of beautiful). It takes so much ceremony to do things you would do without any thought in other languages . Initiating a mutable set Python `a = {1,2}` What most Java programmers do ``` var a = new HashSet (); a.add(1); a.add(2); ``` S…

`var a = Set.of(1, 2)` works just fine in Java.

I mentioned "mutable" in my comment
Post reply on HN