News for hackers. Stuff that matters.
Re:Java 18 / JDK 18: General Availability by kaycebasques on Tuesday March 22, 2022 @11:12AM (#30767045)
This is tangential and possibly too open ended to be productive but worth a shot anyway. Why is Java so popular? I know of a major Silicon Valley company that's migrating their backend to it. Why Java over other languages? Or maybe there's not really other viable options?

I'm speaking as someone who spent the last 6 years focused on frontend web technology.

Re:Java 18 / JDK 18: General Availability by paulmd on Tuesday March 22, 2022 @11:42AM (#30767462)
To echo others: relatively good performance, incredible tooling/deployment infra (really best-in-class), intercompatibility with tons of other languages built on top of the JVM such that it can be functional/do actors/whatever your other weird approach is, relatively high productivity due to a large library base (not just the standard library but also a huge amount of stuff written to support android apps), and ease of hiring/replacement.

But to throw another onto the pile, Java being statically compiled makes it a lot easier to comprehend a larger codebase that you didn't necessarily write yourself. The history of dynamically-typed languages is basically getting to a certain critical size and realizing there's some merit to a well-defined, compiler-checkable code interface and then retconning it in - this happened with Facebook (Hack-lang), with Typescript/CoffeeScript (Google), and I think there's one for Python now too.

So yeah, basically people like Java because it's fast and versatile, because it's got a Pythonesque amount of stuff already written for it, and because it's got features that are oriented towards bigger teams with more turnover/etc that make it practical for business reasons.

Re:Java 18 / JDK 18: General Availability by pianoben on Tuesday March 22, 2022 @11:49AM (#30767547)
> with Typescript/CoffeeScript (Google)

cough Microsoft did Typescript, actually

https://en.wikipedia.org/wiki/TypeScript#History

Re:Java 18 / JDK 18: General Availability by azth on Tuesday March 22, 2022 @01:49PM (#30769197)
> relatively good performance,

That's kind of downplaying it right? Outside of "native" languages like C, C++, Rust, fortran, Java blows everything else out of the water.

Re:Java 18 / JDK 18: General Availability by jollybean on Tuesday March 22, 2022 @07:01PM (#30772713)
Javascript in V8 is more performant than Java on a lot of tasks, and almost always 'sooner'. V8 is focused on 'getting going quickly' and it does, very fast. Java takes some time to optimize for most tasks.

Also, 'performance' isn't really an issue once you are past 'good enough'.

I don't think most devs are worried about Java/Node/Python/Golang performance on the backend for most apps. Obviously not always the case, but in most instances, it's not a primary concern.

Frankly, these days, when I think about 'performance' I think about 'developer performance!'. Java downsides in that its bureaucratic by convention, but at least it's super solid and reliable. I really, really wish it were a bight lighter however.

Re:Java 18 / JDK 18: General Availability by azth on Wednesday March 23, 2022 @12:02AM (#30774808)
> Javascript in V8 is more performant than Java on a lot of tasks,

Source? I constantly see companies switching from the likes of python and javascript to compiled languages after they reach a certain scale.

I find Java to be extremely developer friendly, especially nowadays with features like pattern matching, records, switch expressions, and the upcoming project Loom

Modern frameworks like quarkus.io are also a step in that direction. You might also want to check out https://jodd.org/.

Re:Java 18 / JDK 18: General Availability by jollybean on Wednesday March 23, 2022 @06:32AM (#30776982)
Source? Reality! :)

I've built V8 instances and run some tests, but you don't need to do that.

Just write some roughly equivalent code and run it in Chrome vs. JVM and see for yourself. It's not nuance or controversial, it will really 'stick out'.

In basically all cases, V8 will 'get fast very quickly', it reaches a high level of performance on the second or 3rd iteration of a bit of code, whereas Java takes thousands of iterations.

That's a very, very broad and crude generalisation, but you'll see it very clearly if you just try it yourself.

It actually does make a difference depending on what you are doing as well - if you're running as server that uses the same code paths all day long, and executes them 1K times per minute, well then Java is fine. But for things like UI I particular where yo need the code to react it's a problem.

'Developer friendly' and 'modern frameworks' are a another question.

Re:Java 18 / JDK 18: General Availability by kaba0 on Wednesday March 23, 2022 @02:54AM (#30775726)
Javascript is much closer to java than to python in terms of performance. And due to the variability of the JIT compilers, it can sometimes be faster than java, but generally the latter wins out.

But the parent poster is right that the two teams did choose a different workload to optimize for, V8 being fast faster while java taking more time to JIT compile a region, but that is mostly due to the difference between their most-common uses, running websites’ code as soon as they load vs mostly running on huge—ass servers with sometimes terabytes of RAM.

Re:Java 18 / JDK 18: General Availability by pulse7 on Wednesday March 23, 2022 @04:00AM (#30776122)
Java is typed, JavaScript is not typed. You can make more performance optimizations if you know types. So this claim is unlikely to hold...
Re:Java 18 / JDK 18: General Availability by jollybean on Wednesday March 23, 2022 @06:28AM (#30776955)
Sorry, but this is textbook.

Go ahead and run some code on V8 and the equivalent Java.

You'll notice V8 is 'extremely fast' at getting up and running, while Java takes quite some time - often thousands of iterations of a specific bit of code before it optimises.

Re:Java 18 / JDK 18: General Availability by igouy on Wednesday March 23, 2022 @01:26PM (#30780961)
Re:Java 18 / JDK 18: General Availability by jollybean on Thursday March 24, 2022 @10:04AM (#30789915)
Oi Vei, I literally said 'fast at getting up and going' and 'over time Java is more optimised'.

Those tests ultimately measure 'peak performance'.

Java takes much longer to reach that level than V8.

Given the fact that a lot of software does not run for a long period of time, and especially UI/Web code (and possibly serverless), the net result is that V8 is basically faster. It gets too near 100% performance after 1 or 2 iterations. Java takes 1000's of iterations.

For many applications, the 'advantage of being fast soon' considerably outweighs any kind of incremental performance benefit that Java might offer over time.

This is mostly true for UI software.

V8 'is fairly quick, and right away'. Java is 'sticky and slow for a bit, and then a bit faster over time but it's not noticeable'.

V8 is a regular car: stops and starts as needed. Java is a race-track stock car - accelerates up to a high speed and stays there. You don't need a race-track car to do food delivery, because the added peak performance is pointless.

Re:Java 18 / JDK 18: General Availability by igouy on Thursday March 24, 2022 @11:32AM (#30791295)
You "literally said" so much, but not anything specific that you've measured and others could measure.
Re:Java 18 / JDK 18: General Availability by kevincox on Tuesday March 22, 2022 @02:13PM (#30769451)
"If you exclude the well performing languages java performs excellently."

But that is what I think OP means. It isn't top tier performance, but it is in the second tier which I wouldn't argue for qualifying for "relatively good".

FWIW I find that languages tend to fall into a couple rough performance groups:

- Native at about x1 performance: C, C++, Rust, Fortran

- Compiled GC at about 2x performance: Java, Go, Haskell, Lisp

- Dynamic at 20-50x native performance: Python, Ruby...

JS is a weird one that varies a lot depending on your workload and can sometimes look similar to compiled GC performance.

Re:Java 18 / JDK 18: General Availability by igouy on Wednesday March 23, 2022 @01:18PM (#30780858)
Re:Java 18 / JDK 18: General Availability by paulmd on Tuesday March 22, 2022 @08:49PM (#30773535)
(parent here)

Yeah, I'd agree (with the sibling as well). Obviously native code is faster but Java is about as fast as it gets for a managed language. It's massively fast (these days) in comparison to, say, Ruby. Python manages to do relatively OK by throwing away any sense of threading and the synchronization of internals that might entail but it's still significantly slower than Java.

Speaking of which that's another advantage of Java. Threading works basically as expected, and now it's even got modern promise/future APIs. Python's "just clone all your memory and do everything through IPC" is super clunky in comparison.

In many cases, that's also inherited by other JVM languages, and interop is really cool there too. You can use Java libraries in your Scala/Kotlin/etc, or call those routines from your Java code. It's not just one language, it's all the languages on one engine, and they all run decently fast for what they are.

C#/DotNet is really fast too (I would say faster than Java if anything) and it's pretty similar to Java in most ways. Bytecode, JITed, static typing, etc. They also got the second-mover advantage, to see all the things Java did wrong and fix them - like checked exceptions, or the clone() interface. On the other hand, at least as of 10 years or so ago, the tooling was absolutely primitive compared to what's out there for JVM stuff (and at the time it was all tied to Windows). Maybe that's changed with Roslyn but they're coming from behind, and Java has been around for a long time and it's tough to overcome that inertia.

Re:Java 18 / JDK 18: General Availability by azth on Wednesday March 23, 2022 @12:08AM (#30774834)
C#/.NET are cool. Ironically enough, Java is getting the second-mover advantage when it comes to green threads by means of Project Loom. Forgoing async/await for a much better experience.
Re:Java 18 / JDK 18: General Availability by munificent on Tuesday March 22, 2022 @12:42PM (#30768339)
I think it's a combination of four things:

1. GC is an enormous productivity improvement for applications whose performance characteristics can afford it. Seriously, I can't think of a single programming language feature/concept/technology that makes a bigger difference in developer velocity than memory safety and GC.

2. Static types are also a large productivity improvement for developers comfortable using them and the kinds of projects that benefit from them (large, multi-dev, multi-year).

3. Imperative and object-oriented. Java is imperative in the small, which is familiar to most developers and seems to strike a balance of letting developers write correct code with good performance. Java is OOP in the large and for many classes of applications, that's been a wildly successful way of organizing code and lowering the cognitive overhead.

4. Path dependence. The past largely determines the present. We don't reset all of our technology choices and start from scratch at the beginning of each fiscal quarter, so the languages that were widely used tend to stay the languages widely used.

Java was the first heavily engineering and marketed language that featured GC, static types, and OOP, so it got big and continues to stay big.

I also think it's a pretty decent language. The things people don't criticize about Java are mostly complaints about a certain style of programming in the 90s and less the language itself.

Re:Java 18 / JDK 18: General Availability by paulmd on Tuesday March 22, 2022 @05:23PM (#30771743)
> I also think it's a pretty decent language. The things people don't criticize about Java are mostly complaints about a certain style of programming in the 90s and less the language itself.

(assuming that's a typo there, the things people don't like/the things people criticize?)

I disagree on that point, I think the language itself was a problem. Java 6 and prior were very very verbose and very very slow. I think that really changed with JDK 7/8, but the java we know today isn't the java of the 90s.

Even then, to some extent that problem hasn't gone away, it's just been papered over with frameworks and library code. Like honestly even as a java dev, I couldn't tell you off the top of my head the exact code to open a file, read each of the lines, and then close everything, or the right way to open a JNP connection to RabbitMQ or something. Anything touching files or sockets is still an absolute nightmare of boilerplate code, inputstreams, filestreams, printwriters, try/catch, and mother. fucking. IOException. thrown everywhere. But you don't care, because you just call Apache commons-io or Spring RestTemplate.

And that has contributed to some criticism of its own. Spring tends to turn into architecture-astronaut crap, like everyone's favorite AbstractSingletonProxyFactoryBean.

> Java was the first heavily engineering and marketed language that featured GC, static types, and OOP, so it got big and continues to stay big.

The other quiet boost that people don't talk about is Android. Tons of libraries get written with the intent of being used in some android app somewhere, but you can use that equally much on desktop/server. It really really helps the rapid-prototyping aspect of Java that ~half the smartphones in the world are running Android.

Re:Java 18 / JDK 18: General Availability by vips7L on Tuesday March 22, 2022 @05:48PM (#30772004)
> exact code to open a file, read each of the lines, and then close everything

    var lines = Files.lines(Paths.get("file.txt"));
or if you want to be extremely cautious:

    try (var lines = Files.lines(Paths.get("file.txt"))) {

    }

I agree about IOException though. It's the bane of my existence :) The amount of times I have to rethrow UncheckedIOException is far too high.
Re:Java 18 / JDK 18: General Availability by munificent on Tuesday March 22, 2022 @06:50PM (#30772641)
> (assuming that's a typo there, the things people don't like/the things people criticize?)

Oops, yes, sorry.

> Java 6 and prior were very very verbose and very very slow.

It's kind of verbose, when looking at it from today's perspective, but at the time I didn't think it was that bad. I think they deliberately tried to be less cryptic and more wordy than C/C++ (which can often be impenatrable). I think they overcorrected for that, but I don't think the language is interolerably verbose.

Performance was definitely bad until Lars Bak and company showed up and wrote HotSpot. But almost every managed language at the time had poor performance. It was certainly painfully slow compared to C and C++ but... what wasn't?

> I couldn't tell you off the top of my head the exact code to open a file, read each of the lines, and then close everything, or the right way to open a JNP connection to RabbitMQ or something.

I mean, I couldn't tell you how to do that off the top of my head in just about any language. Except C. But, of course, the code I would write for C off the top of my head is simple and wrong because it doesn't handle all of the various ways IO can fail.

Networking and file systems are honestly just kind of grungy. You can paper over it with simple APIs but what you end up with is code that looks pretty but can fail in obscure ways.

> try/catch, and mother. fucking. IOException. thrown everywhere.

Yeah, checked exceptions were simply a mistake. I don't fault them for trying to fit exceptions into the static type system. It was a cool, ambitious idea. At the time, no one really had a sense of how the ecosystem would settle around using exceptions. In practice, it ended up being more trouble than it's worth.

> The other quiet boost that people don't talk about is Android.

Android is definitely keeping it popular these days, but Java was huge because of server development before Android came along.

Re:Java 18 / JDK 18: General Availability by igouy on Wednesday March 23, 2022 @01:49PM (#30781218)
> But almost every managed language at the time had poor performance.

Slow compared to Smalltalk. Slow compared to Lisp.

Re:Java 18 / JDK 18: General Availability by munificent on Wednesday March 23, 2022 @02:47PM (#30781841)
Depends on which implementations you're talking about.

But even fast Smalltalks weren't very fast relative to C, just relative to most other dynamic languages. And, of course, the people who made Smalltalk fast ended up making Java even faster.

Re:Java 18 / JDK 18: General Availability by igouy on Thursday March 24, 2022 @11:28AM (#30791238)
> relative to C

Seemed like you'd shifted your comparison to "almost every managed language."

So Java at-the-time compared to Smalltalk and Lisp at-the-time.

I suppose Haskell at-the-time, OCaml at-the-time :-)

Re:Java 18 / JDK 18: General Availability by munificent on Thursday March 24, 2022 @05:31PM (#30795575)
I did say "almost every" and not "every". :)

Were there fast managed languages? Yes, a couple.

Were there fast managed object-oriented languages? Yes, Self and a Smalltalk or two.

Were there fast managed statically typed languages? Yes, SML and Haskell.

Where there fast, managed, statically typed, and object-oriented languages? Not many. Maybe Eiffel, but that was shackled by DbC dogmatism and probably some amount of Eurocentricity. I don't think Ada had GC back then and if your complaint is that Java is too verbose, you sure as heck aren't gonna like Ada.

Re:Java 18 / JDK 18: General Availability by igouy on Wednesday March 23, 2022 @02:07PM (#30781438)
> Java was the first heavily…

Free-as-in-beer?

Re:Java 18 / JDK 18: General Availability by giaour on Tuesday March 22, 2022 @11:23AM (#30767195)
Java values backwards compatibility very highly, so if something runs today, it's likely to keep running without modification on future JVMs. (Though the 8->9 transition was pretty rough for some.) Compiled Java artifacts are usually portable across OSes and CPU architectures, so your build pipeline can be pretty simple even if your infrastructure is not.

JVM performance is generally fine, and the language prevents you from introducing whole classes of memory safety bugs. You can still shoot yourself in the foot with native (JNI) extensions, but the decent performance of the JVM makes developers use JNI far less frequently than, say, Python or Ruby devs reach for compiled libraries.

JVM byte code decompilation is fairly trivial, so tools for the security scanning of artifacts are cheaper and more fully featured than similar tools for scanning machine code.

Re:Java 18 / JDK 18: General Availability by paulmd on Tuesday March 22, 2022 @08:44PM (#30773496)
> Java values backwards compatibility very highly, so if something runs today, it's likely to keep running without modification on future JVMs.

this has been the case in the past, but Java is gritting its teeth and making some breaking changes in the JDK11/16/18 era.

libraries that mess with the unsafe/internal namespaces are the most prominent example - there are a ton of legacy libraries that are going to break from that change unless updated - but there's also a big push for modules and for classes to encapsulate themselves more strongly.

Re:Java 18 / JDK 18: General Availability by kaba0 on Wednesday March 23, 2022 @02:58AM (#30775746)
Which is essential for the longevity of a platform. You can’t further develop the JVM if you are bogged down by code depending on the internals. Encapsulation by modules is hugely important, and if we are honest, anything that depended on internals were prone to bugs anyways. Sure it sucks, but they will update sooner or later
Re:Java 18 / JDK 18: General Availability by ok123456 on Tuesday March 22, 2022 @12:02PM (#30767718)
> Java values backwards compatibility very highly, so if something runs today, it's likely to keep running without modification on future JVMs.

Then why do I have to have multiple JVMs installed, which I need to go through via trial-and-error, if I'm given some random java application?

Re:Java 18 / JDK 18: General Availability by stevoski on Tuesday March 22, 2022 @12:33PM (#30768216)
> Then why do I have to have multiple JVMs installed, which I need to go through via trial-and-error, if I'm given some random java application?

You don't. Almost any Java program written ever will run on Java 18.

Re:Java 18 / JDK 18: General Availability by ok123456 on Tuesday March 22, 2022 @12:38PM (#30768278)
JavaFX isn't guaranteed to be in a JVM. You run into "deprecated" APIs that were removed. JVM options change, and that breaks how things are deployed. If the JVM were a stable target a site like http://whichjdk.com/ wouldn't be necessary.

This is just how things are. It's Java fanfiction to say this isn't the case, and necessitates having multiple JVMs installed.

Re:Java 18 / JDK 18: General Availability by giaour on Tuesday March 22, 2022 @01:33PM (#30769008)
http://whichjdk.net seems to be a site that tells me not to use the Oracle JDK without a license? There's a listing of which releases were the first to include certain language features, but it seems to mainly be giving advice around JDK vendors, not JDK versions.

There are two kinds of backwards compatibility at play: BC for compiled artifacts (let's call this Java ABI compatibility) and BC for language APIs (Java API compatibility). I have run into issues trying to compile an application with one JDK version and then run it on another (specifically, I believe JVMs will generally not run artifacts compiled with a later JDK version), but API backwards incompatibility is really rare in Java.

I do recall having to do a bit of cleanup when a previous project moved from Java 8 to Java 11, since a ton of deprecated APIs were pruned in Java 9, but those APIs were published by the JDK authors as standalone JARs, so I could remediate by adding a maven dependency. JVM backwards compatibility isn't perfect, but it's a much more stable target than other languages I've worked in.

Re:Java 18 / JDK 18: General Availability by _old_dude_ on Tuesday March 22, 2022 @12:46PM (#30768395)
Azul (not affiliated) provides JDKs with JavaFX bundled

https://www.azul.com/downloads/?version=java-17-lts&package=...

Re:Java 18 / JDK 18: General Availability by paulmd on Tuesday March 22, 2022 @08:45PM (#30773504)
an odd one for me is JNLP - I have a motherboard with IPMI and they chose to do that through JNLP, which makes it an absolute pain in the ass to use the interface.
Re:Java 18 / JDK 18: General Availability by Tomte on Tuesday March 22, 2022 @04:46PM (#30771307)
Unfortunately, FreePlane demands Java 8, I think.
Re:Java 18 / JDK 18: General Availability by NoSorryCannot on Tuesday March 22, 2022 @12:30PM (#30768166)
I don't know, why do you?

There are occasionally breaking changes but most old jars out there will run fine in the latest runtime, so the answer to your question is going to depend on how squirrely your use case is.

Re:Java 18 / JDK 18: General Availability by jakebasile on Tuesday March 22, 2022 @11:20AM (#30767152)
The JVM is great. It's easy(-ish) to deploy and there is a library for anything you can possibly think of, probably more than one, on Maven. It handles large throughput and big memory usage very well and is extremely tunable.

Using the JVM doesn't mean you're limited to Java anymore, and hasn't for a long time. I have built software for the JVM for the past 6+ years nearly exclusively in Clojure with only a few moments where I needed to dip down into Java proper.

Re:Java 18 / JDK 18: General Availability by packetlost on Tuesday March 22, 2022 @11:44AM (#30767486)
Can confirm. Been learning Clojure lately (after using Python for a long time) and it's great. That being said, the JVM is a bit chunky in terms of disk usage and when you get into really high performance things, tuning heap space and whatnot is a pain (I'm looking at you ElasticSearch), but it really is a fantastic piece of engineering.
Re:Java 18 / JDK 18: General Availability by junon on Tuesday March 22, 2022 @11:19AM (#30767136)
The language is simple. Reasonable performance, lots of opportunities to tune that performance without changing code. Great error handling. Works across all platforms in most cases. The tooling has a long standing reputation for being incredible, given what Eclipse and Jetbrains have done for the community. It integrates nicely with native code, and is easy enough to interface with (compared to e.g. Node.js and python, which have hellish bindings). Strictly typed, which has a lot of benefits. Lots of long-standing libraries that have been battle tested and still work even today. Great ability to mock, inject, and invert dependencies.

No language is perfect of course, the point isn't to start a war. I don't personally use Java for my own projects anymore but I can see why it's very attractive.

Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @11:25AM (#30767215)
Great error handling? What does that mean? Checked exceptions seem cool at first, but are really just nonsense… as your only real way of dealing with this is:

1. Catch, log and rethrow, or

2. Wrap as a runtime exception (so you don’t have to change every method signature up to main())

Sure, there’s option 3: catch and handle… but this is used 1/50 times, and the ergonomics of (2) overwhelm the utility of this.

BTW, vavr is nice. Just, “run it all” and optimize for the golden path. If there’s an error account for it locally.

Re:Java 18 / JDK 18: General Availability by Slartie on Tuesday March 22, 2022 @11:56AM (#30767633)
Anyone not seriously considering option 3 as the default, with options 1 and 2 being the exception that one must have good reason to take, automatically disqualifies himself as ignorant of proper error handling.

Of course you catch and handle errors. Or at the very least you must think about whether it makes sense to handle an error on the current abstraction level that you are on, which means you must always consider option 3. Only if you decide that it's not possible or doesn't make sense to handle it ("I am too lazy" is not a reason to not handle it!) you decide whether you need to throw it one level up the stack. And if doing that is the sensible thing, you think about whether you want to make the exception part of the API of whatever you currently write or not. If you want to, you throw the exception without doing anything (most of the time you don't even log it, because you understand that the receiver at the end, the one who finally handles it, is responsible of logging it, otherwise you get multiple logs of the same exception written out just because someone sprinkled logging into several abstraction layers). If you want to hide the exception type somehow, you wrap it in a more fitting exception that's explicitly or implicitly part of the API of whatever you're writing, and throw that one. That can, but doesn't have to be, a runtime exception.

I really don't get what's so hard about exception handling. Java's exceptions are a pretty good analog to how one must model proper error handling in multi-layered software applications anyway, regardless of the programming model used to implement it.

Re:Java 18 / JDK 18: General Availability by isbvhodnvemrwvn on Tuesday March 22, 2022 @12:01PM (#30767712)
By your opinion 90%+ of Java ecosystem is ignorant of proper error handling, which in itself is a statement on how poorly this method of error handling is looked at.
Re:Java 18 / JDK 18: General Availability by Slartie on Tuesday March 22, 2022 @12:09PM (#30767830)
I have seen quite a bit of code in the Java ecosystem over more than 15 years, but far less than 90% of it. And even in the small slice that I've seen, I'd say the quota of ignorant error handling is way lower than 90%. Especially the higher-quality Java libraries that people reuse over and over usually behave okay with regard to exception handling nowadays.
Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @04:43PM (#30771262)
sure. consider me ignorant of proper error handling.

looks like the "true scotsman problem", though. i'm using state of the art packages like jgrapht which throw runtime exceptions, and i'm manually catching those runtime exceptions, pattern matching on the exception messages, and trying to handle.

when the community doesn't use the API, it's a tragedy of the commons problem. there's a lot of grey area between what constitutes a runtime exception vs. a checked exception. it's all very subjective!

Re:Java 18 / JDK 18: General Availability by pritambarhate on Tuesday March 22, 2022 @11:32AM (#30767308)
>> 1. Catch, log

This is not as useless as it sounds. You can analyse the logs and find out why these exceptions are occurring. A lot of times these lead you to subtle bugs which you might not have noticed otherwise.

Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @04:36PM (#30771177)
sure. or if using something like Vavr... catch a bunch of 'em all at once.

``` Try.success(foo. .map(...) .mapTry(...) .map(...) .mapTry(...) .onFailure(e -> LOGGER.warn("Failed %s", e) .get() ```

Re:Java 18 / JDK 18: General Availability by junon on Tuesday March 22, 2022 @11:26AM (#30767228)
Was referring more to structured stack traces. You're able to shoot yourself in the foot in any language's error handling system - quite trivially at that.
Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @11:29AM (#30767267)
But the problem is that checked exceptions create the same “what color is your function” problem for errors.
Re:Java 18 / JDK 18: General Availability by pkolaczk on Tuesday March 22, 2022 @12:18PM (#30767971)
That's not the real problem with checked exceptions in Java. You actually have the same problem with any result type in a language with static types and mandatory explicit types in function signatures - you change one type and you have to adjust the callers, sometimes many levels above. This is just life ;)

One of biggest troubles with checked exceptions is that in Java it is impossible to generify them the same way you can do with argument and return types. You can't write a generic filter or map function that throws the same checked exceptions as the lambda (or any other interface object) that gets passed as an argument. This makes it impossible to use code that throws checked exceptions in some contexts and forces developers to wrap them in RuntimeException.

And because those situations are extremely common these days, especially after some FP techniques influenced how Java code is being written, almost noone uses checked exceptions and you typically get runtime exceptions flying around the whole codebase. Which are even worse - they turn very quickly into an unmaintainable mess - because now any function can throw just anything at any time, and that's not even explicitly visible.

And here we get to the next big problem with exceptions (not just checked exceptions): they add a high number of alternative control flows you need to analyze in addition to the main "happy path" of the program. An exception can happen anywhere and it might leave the data in incorrect, partially updated state. In reality many devs simply pretend the problem doesn't exist, and they check the happy path only. In languages with no exceptions, a function can exit only by an explicit return - and that is way more readable and easier to analyze.

And the last thing which seems to be more a cultural problem, rather than a Java problem, is that somehow most Java programs communicate typical, expected problems with ugly and mostly useless exception stacktraces. Can't connect to a host? I get a stacktrace. File not found? Two screens of stacktraces... That's IMHO a terrible approach to error handling. As a user I am totally uninterested in what code was being executed when something failed (that should be reported only for bugs so the developers can fix). I'm interested in getting a human-readable message with context helping me understand what went wrong and how to fix it.

Re:Java 18 / JDK 18: General Availability by simion314 on Tuesday March 22, 2022 @11:39AM (#30767421)
>But the problem is that checked exceptions create the same “what color is your function” problem for errors.

Compared to "SEGFAULT at 0x000000 in some xxx.dll" having to handle exception and having readable stack traces is a productivity win.

Re:Java 18 / JDK 18: General Availability by sabageti on Tuesday March 22, 2022 @12:48PM (#30768420)
It isn't? You have a function red that doesn't throws anything you use a function blue that throws checked exceptions you handle the exception and it's all. The red functions doesn't become blue.
Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @04:48PM (#30771330)
if the "red" function isn't successful, than you're mapping that error to what? a RuntimeException? great – you've now escaped the indirection with the original solution – just use RuntimeExceptions.

map it to another checked exception and you now have a "blue" function. and, you also have another layer of abstraction in your errors.

if you can't actually handle the error, skip the circus and just let the exception propagate to a general error boundary (alongside all those RuntimeExceptions you're unaware of).

It's a deep ocean, your defense mechanism of guarding against Checked Exceptions is a small fraction of all exceptions.

To be fair, I did really like the idea of checked functions when I first started using Java. But in practice, it's just too hard to tell what operations should be Checked / Unchecked (sometimes).

Re:Java 18 / JDK 18: General Availability by vips7L on Tuesday March 22, 2022 @12:01PM (#30767705)
No one really uses checked exceptions. But I agree they suck, IOException is the bane of my existence. It's the #1 reason why I don't like Rust or Go. Checking errors is dreadful.
Re:Java 18 / JDK 18: General Availability by pkolaczk on Tuesday March 22, 2022 @12:24PM (#30768081)
> Checking errors is dreadful.

That's true, but that doesn't mean we should pretend the problem does not exist. Using unchecked exceptions is sweeping things under the carpet. Generally unchecked exceptions should be used only for bugs (array index out of bounds) or unrecoverable situations (JVM crash, no memory). I/O does not belong there.

Re:Java 18 / JDK 18: General Availability by ahtihn on Tuesday March 22, 2022 @02:04PM (#30769360)
Okay,so what's a better way to do error handling?

Returning an Either<Result, Error> is pretty much the same thing conceptually. Either you propagate the error or you handle it.

Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @04:46PM (#30771308)
I'm just suggesting that Checked Exceptions aren't well enough adopted and there's grey area between what constitutes a checked / unchecked exception.

I have no problem with Either<Error, Result> though.

Re:Java 18 / JDK 18: General Availability by jmyeet on Tuesday March 22, 2022 @11:17AM (#30767107)
Because Java is stable and mature, has well-understood performance, is statically-typed, has a proven track record when it comes to backwards compatibility, is reasonably fast and has lots of library and tooling support. Additionally lots of people know it.

Some complain about verbosity. It's really a non-issue particularly in a modern IDE and not worth making a language decision over.

Not everything has to be new and sexy.

Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @11:27AM (#30767242)
Definitely an issue in 8. My hack is to call everything an `int`, write the statement, and go back and let IntelliJ handle the proper name, adding the import, etc.

I understand though, that in more recent versions of Java this is taken care of for you.

Re:Java 18 / JDK 18: General Availability by matsemann on Tuesday March 22, 2022 @11:51AM (#30767579)
Why not just write the statement and write `.var`? Like if you write

myService.getSomething().var

and press tab, it will autocomplete it to

Something something = myService.getSomething()

Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @04:33PM (#30771140)
wow. you just blew my mind. thank you.
Re:Java 18 / JDK 18: General Availability by grishka on Tuesday March 22, 2022 @11:38AM (#30767405)
Java is easy to understand and it's hard to shoot yourself in the foot with (no raw memory access, unless you use JNI/JNA). Garbage collector makes memory management a non-issue. Exceptions make error handling easy. OOP is a simple concept and many real-world programming tasks can be laid out as a nice class hierarchy. Java's changes are few (as opposed to some other languages), feel logical (to me at least), and solve real problems. Most of "syntactic sugar" features don't make the code using them less readable.

Java also supposedly runs on everything. And, you could as well write Android apps in it.

Re:Java 18 / JDK 18: General Availability by jraph on Tuesday March 22, 2022 @11:16AM (#30767081)
I'll try: Java is a proven, boring and "easy" language without much surprise, with a big standard library and ecosystem.
Re:Java 18 / JDK 18: General Availability by ape4 on Tuesday March 22, 2022 @11:18AM (#30767120)
Java is great, but here's a surprise:

    if (str1 == str2) {
       // oops
    }
Re:Java 18 / JDK 18: General Availability by junon on Tuesday March 22, 2022 @11:21AM (#30767159)
If you actually understand Java, you'll understand why this is wrong. Only newbies have confusion about this, most of which dissipates when you actually learn the language you're working with. Tired of this 20+ year old "flaw" being used as cannon fodder.
Re:Java 18 / JDK 18: General Availability by dtech on Tuesday March 22, 2022 @11:53AM (#30767601)
Just because something is a well known-flaw doesn't make it a glaring flaw.

There's a reason newer JVM languages like Kotlin use == as an alias for equals instead of reference equality.

Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @12:29PM (#30768147)
What if you are interested in reference equality?
Re:Java 18 / JDK 18: General Availability by __float on Tuesday March 22, 2022 @12:39PM (#30768292)
In practice, how often are you interested in it? C# has `Object.referenceEquals()` because you _may_ want this sometimes. But to have reference equality be the default for something like `==` is a design flaw. Not one that can be fixed now, of course, but it will continue to cause bugs for years to come.

Sometimes, it happens in core Java libraries themselves: https://bugs.openjdk.java.net/browse/JDK-8274779

https://github.com/openjdk/jdk/blob/722d639fad2e4fc6eb2aabd4...

Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @12:53PM (#30768500)
Dunno, I do a fair bit of low level java work, happens every once in a while.

Curiously, I don't do a lot of value-comparisons. Based on grepping in the repo for my search engine, I appear to do one every 1000 lines of code. May just be how I write code though. Some people seem to do that a lot more.

Re:Java 18 / JDK 18: General Availability by LordDragonfang on Tuesday March 22, 2022 @12:50PM (#30768458)
Python uses the `is` operator, which is semantically much more explicit (and arguably correct, though C#'s use of the `is` operator is probably more correct).

edit:

Kotlin uses `===`, which is another good option.

Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @01:01PM (#30768619)
=== seems almost more dangerous. It's a lot easier to tell == from Objects.equals(a,b) than == from ===.
Re:Java 18 / JDK 18: General Availability by wiseowise on Tuesday March 22, 2022 @03:37PM (#30770486)
Seriously?
Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @05:06PM (#30771553)
Yes.

Look, languages are moving away from permitting constructs like "if (x = 1)" because it's difficult to distinguish from "if (x == 1)". Adding "if (x === 1)" into the mix is arguably a step backwards in terms of clarity.

Re:Java 18 / JDK 18: General Availability by Banana699 on Tuesday March 22, 2022 @04:06PM (#30770835)
This is like saying that null references are a non-issue because it have been there since the 1970s and that "true" $LANGUAGE developers never collide head-first into invalid dereferences. If something is ridiculous and un-ergonomic, it stays ridiculous and un-ergonomic no matter what. Reference comparison by default is ridiculous and un-ergonomic.
Re:Java 18 / JDK 18: General Availability by junon on Wednesday March 23, 2022 @07:14AM (#30777246)
Null references exist in every language with the concept of null. It has nothing to do with Java specifically, and Java gives you a lot of information to debug them.
Re:Java 18 / JDK 18: General Availability by jraph on Wednesday March 23, 2022 @01:43PM (#30781156)
That's right, but that also doesn't answer the parent's point to which I fully agree.
Re:Java 18 / JDK 18: General Availability by MBCook on Tuesday March 22, 2022 @12:14PM (#30767903)
For what it’s worth any decent IDE will warn you about that. But as a Java developer you know it’s wrong, Strings are objects and that’s not how you compare objects.

The tricky one is numbers.

Integer == int // fine

int == int // fine

numVarOne == numVarTwo // Uh-oh

In that third example you better make sure they aren’t both boxed objects or BigDecimals.

I’ve almost never seen the string one for some reason. It’s always boxed numbers.

Again, a good IDE is worth a ton.

Re:Java 18 / JDK 18: General Availability by vips7L on Tuesday March 22, 2022 @03:05PM (#30770107)
Integer == Integer actually works... sometimes, as long as you're within the Integer cache. It gets people all the time though.
Re:Java 18 / JDK 18: General Availability by MBCook on Tuesday March 22, 2022 @03:24PM (#30770329)
Yep. I’ve been bitten by that myself. It’s sneaky because it may pass all your unit tests because you’re using small numbers. Then it gets to prod with record number 2718 and kablooie.
Re:Java 18 / JDK 18: General Availability by UncleMeat on Tuesday March 22, 2022 @11:24AM (#30767203)
It is true that C# improved this. Separating primitives and references in Java was definitely an error and it cannot be fixed at this point.

The good news is that a linter trivially detects this bug.

Re:Java 18 / JDK 18: General Availability by msgilligan on Tuesday March 22, 2022 @12:23PM (#30768062)
Actually Project Valhalla is going to fix (well at least improve) this:

https://openjdk.java.net/projects/valhalla/

Re:Java 18 / JDK 18: General Availability by Cthulhu_ on Tuesday March 22, 2022 @11:56AM (#30767629)
Only if you skip all the tutorials and don't use an editor that warns you about it. Which is another selling point for Java; it has the best editor support and quality assurance tools out there. It took years for e.g. Javascript to catch up and it's still a far cry from a proper typed language with tooling.

I mean by that same logic, Javascript will confuse you as well because `{} != {}`, or C++ because of pointer mechanisms and custom operators.

Re:Java 18 / JDK 18: General Availability by Banana699 on Tuesday March 22, 2022 @04:16PM (#30770947)
It's really says a lot that you have to compare with JS or Cpp so that Java comes out on top. Those are 2 extremely flawed languages that are the butts of cliché jokes well-known across every programming circle, their history alone has "HACK" written all over it.
Re:Java 18 / JDK 18: General Availability by jraph on Tuesday March 22, 2022 @11:19AM (#30767139)
Yeah, I hate that about Java.
Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @12:14PM (#30767917)
Eh, I'll take that over <https://dorey.github.io/JavaScript-Equality-Table/> any day.

Boolean.getBoolean, however, now that is a proper Java land mine.

Re:Java 18 / JDK 18: General Availability by azth on Tuesday March 22, 2022 @01:55PM (#30769273)
In addition to what the other posters replied, the IDE will warn you about this.
Re:Java 18 / JDK 18: General Availability by darkhorn on Tuesday March 22, 2022 @07:23PM (#30772915)
Another surprise is it that it has issues on Turkish localized Windows operating systems.
Re:Java 18 / JDK 18: General Availability by kaba0 on Wednesday March 23, 2022 @03:02AM (#30775782)
What do you mean? Can you give a source where I can read more on that?
Re:Java 18 / JDK 18: General Availability by kaba0 on Wednesday March 23, 2022 @06:03PM (#30784072)
Well, I think it’s just the usual gotcha of programmers assuming things about languages that are not true.

Though I’m not sure why wasn’t two new i’s added instead of modifying the latin i? It is a different letter after all in this case.

Re:Java 18 / JDK 18: General Availability by dpratt on Tuesday March 22, 2022 @11:19AM (#30767135)
That’s not an oops. You’re comparing pointers.
Re:Java 18 / JDK 18: General Availability by jraph on Tuesday March 22, 2022 @11:21AM (#30767158)
Still, coming from other languages, it is all too easy to write this and this silently fails without any warning.

This is consistent with the rest of the language, but I'd bet one rarely wants referential equality when comparing strings.

People commenting "yeah but that's because you are a newbie / you are comparing references and you should know better" miss the point I think. I can easily see myself making this mistake while fully understanding what's going on.

Re:Java 18 / JDK 18: General Availability by pritambarhate on Tuesday March 22, 2022 @11:29AM (#30767273)
Linters catch this: https://rules.sonarsource.com/java/RSPEC-4973

Basically the tooling around Java is very evolved and Java static type system helps the IDEs a lot. One of the main reason enterprises prefer Java. Also majority of the tools and IDEs is free for commercial use.

Re:Java 18 / JDK 18: General Availability by __float on Tuesday March 22, 2022 @12:41PM (#30768316)
Re:Java 18 / JDK 18: General Availability by nsxwolf on Tuesday March 22, 2022 @04:54PM (#30771402)
I learned this 25 years ago when I got started with the language. It tripped me up once, I learned about how references work in Java, and that was that.

We are expected to learn about our tools.

Re:Java 18 / JDK 18: General Availability by jraph on Tuesday March 22, 2022 @07:19PM (#30772874)
> We are expected to learn about our tools.

I hope making mistakes is ok though?

I learnt C years before Java, it's also the first language I properly learnt. And a little bit of C++ too, so I've known the concepts of pointers and references way before learning Java. In C, you also either do pointer equality or explicit value equality (with strcmp) for string equality tests. I never had any issue understanding how things work in Java. It's not about learning anything. It's about doing mistakes. And I won't take "you should know better" as a counter argument to a mention of some rough edge in an API or a programming language. It's like Javascript: you might know the differences between == and === in Javascript full well, but still happen to write == by mistake because you just wrote some C/Java/Python code just before. I'll probably not forget about .equals(...) in Java most of the time but the fact that == would be silently accepted and not do what is wanted is still a bit concerning (and .equals(...) is ugly, too).

A linter will do indeed and that's a fair point. I'd argue that linters are there to work around rough edges of programming languages, but that's fair enough too, every programming language has its gotchas and I'll accept considering a programming language + its linter(s) instead of a programming language alone. However, that's still not ideal because you might have to work on non linted code and deal with these gotchas without any safety net.

I hadn't thought about number comparisons (mentioned in other comments) but that's even worse indeed.

It's no wonder Kotlin and Groovy both chose value comparison for ==.

Re:Java 18 / JDK 18: General Availability by jrsj on Tuesday March 22, 2022 @11:29AM (#30767270)
Most editors will warn you about this now as soon as you type it
Re:Java 18 / JDK 18: General Availability by dtech on Tuesday March 22, 2022 @11:54AM (#30767606)
Reference equality being the default instead of something you very explicitly have to ask for is a flaw.
Re:Java 18 / JDK 18: General Availability by nkzd on Tuesday March 22, 2022 @11:39AM (#30767429)
Really? You are only "confused" by this if you are very new to programming in general.
Re:Java 18 / JDK 18: General Availability by lkrubner on Tuesday March 22, 2022 @11:30AM (#30767280)
For me the choice is really about the JVM, rather than going with Microsoft and .NET. I work mostly in Clojure, which runs on the JVM. But I have the whole universe of Java libraries available to me. Whatever flavor of language you are into, you will find something that runs on the JVM.

The competition includes languages like Rust, Go, Haskell or Erlang. Most of these lack the languages that you'll find on the JVM, so it really is a question of what you are trying to do. Go is certainly interesting in some places, especially if you want a binary that is entirely self sufficient. Each of these languages is interesting, though of course one has to wonder about hiring, whereas finding developers who've worked on the JVM is easy enough.

Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @11:20AM (#30767153)
I think it has a relative speed performance over languages that are interpreted (runtime).

It also has an ecosystem of tooling to monitor and profile built both into the JDKs and by teams across Silicon Valley (eg first class bazel support).

I’m in one of these companies now, and while I’m certainly productive using Java, it’s also got huge downside in the community which these companies don’t really care about.

Never have I seen so much cargo cult practice. The ecosystem isn’t great, with hard to google docs and everything pointing you to a poorly written baeldung article.

Java gets no one excited. And, it gets no one fired.

Re:Java 18 / JDK 18: General Availability by fifticon on Tuesday March 22, 2022 @11:26AM (#30767230)
Actually, i like it for basic desktop apps, because it just works, and i stay clear of the last 12 years of front-end dumpster fires, where nothing that is over 18 months old, can build, compile or get support anymore. In my day job, I inherit "fun" tasks as 'get this thing someone glued together with webpack4 and frontend-du-jour to work with webpack5 in 2022. Java thank you, any day of the week.
Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @11:34AM (#30767356)
There are a lot of problems in the JS and Swift communities, as there are for Java.

I think you’ve got to meet your customer where they are, and if you can ship Java desktop apps, and they’re happy… keep going.

But you’re not shipping apps to their iPhones using Java. It’s either JS or Swift.

And, on Android it’s JS or Kotlin.

So the common target is JS.

Re:Java 18 / JDK 18: General Availability by ohgodplsno on Tuesday March 22, 2022 @12:34PM (#30768228)
Or Kotlin Multiplatform, which generates .frameworks/cocoapods/spm files that you can use, and all you have to do is write your UI layer in Swift.
Re:Java 18 / JDK 18: General Availability by native_samples on Tuesday March 22, 2022 @02:08PM (#30769394)
You can ship to iOS with Java actually. That's the business model of Gluon:

https://gluonhq.com/

It's a combination of JavaFX, a custom controls library that implements Material Design and GraalVM native image. Whether you want a non-native UI toolkit on iOS is a separate matter, but it can be done technically.

In fact, you can ship JavaFX apps to the web too. It doesn't compile to megabytes of JS either - instead, the JavaFX app runs on the server and the UI is projected to divs and SVG elements on the fly. The browser provides native scrolling and text selection. If you have low latency to the server (e.g. same continent) it can work remarkably well. Check out https://www.jpro.one/ - the entire website is a JavaFX app.

Re:Java 18 / JDK 18: General Availability by matsemann on Tuesday March 22, 2022 @11:49AM (#30767539)
I feel like those crying cargo-cult or enterprise never stopped to look at the alternatives they use. Like Django or Rails. It's in many ways worse than java when it comes to conventions, abstractions doing magic, and weird rules for structuring code.
Re:Java 18 / JDK 18: General Availability by dfee on Tuesday March 22, 2022 @05:05PM (#30771533)
i've got tons of open source packages on my github with interpreted languages :p

But yeah, I guess i first started using Django ~2008 if I recall correctly, and switched over to Pyramid in 2010. Since then, I've used many other frameworks – in Python, Ruby, JS, C#, Java, and Go. Regardless of the language, I always try and go closer to the metal when I can.

I think your assessment about the others being potentially worse is fair: they're all bad in their own ways. I think it just takes time (and experience across many different teams) to develop good taste.

Re:Java 18 / JDK 18: General Availability by marginalia_nu on Tuesday March 22, 2022 @12:28PM (#30768136)
I can tell you why I choose Java for my projects:

* It's very fault tolerant. In almost every case C++ would mushroom cloud, Java can walk it off. It's easy to write code that cleans itself up on error. try-with-resources is great.

* Modern JVM JIT and GC are pretty damn good, and the tooling is great.

* It's very boring and stable. I see this as the killer feature. Cool is a conserved quantity. It's extremely hard to write cool software in a cool language, as that attracts cool developers too busy getting cool jobs to maintain their cool framework you depended on. There's a lot of mature high quality libraries available. APIs are stable, stuff very seldom breaks. You can often use code that's 10-15 years old just fine. This has changed a bit lately, but it's still extremely reliable.

There are drawbacks as well, primarily memory mapping files is difficult, some of the aforementioned libraries are a bit bloated as well and overall the language sort of encourages large complicated solutions to simple problems.

Re:Java 18 / JDK 18: General Availability by runevault on Tuesday March 22, 2022 @11:21AM (#30767166)
Language with a fast runtime minus startup (although maybe they've fixed the startup since I last looked) that is incredibly tunable to fit your specific needs for good performance profile, while not needing to manage raw memory the way c or c++ would.

Personally I prefer c#, but a lot of places already were using Java in significant ways before c# became good (IMO 2.0ish) and saw no reason to change.

Re:Java 18 / JDK 18: General Availability by kaba0 on Tuesday March 22, 2022 @12:41PM (#30768327)
Java’s startup only slows down when a ton of classes have to be loaded, e.g. that’s why Clojure’s repl takes quite some time as you are loading two standard libs.

For a simple hello world it is below 0.1s.

Re:Java 18 / JDK 18: General Availability by pkolaczk on Wednesday March 23, 2022 @03:41AM (#30776031)
But noone cares about hello world. You're not building hello-worlds in real life.

Slow startup time is a problem in automated testing of big codebases - when you aim to test the whole codebase, but each test alone does not stress any code path hard enough for the hotspot compiler to kick in. So basically most of your Java code in testing runs in interpreted mode, which is like 20x-100x slower than properly compiled and optimized C/C++/Rust.

Re:Java 18 / JDK 18: General Availability by kaba0 on Wednesday March 23, 2022 @12:24PM (#30780145)
That’s just not how it works.

If no code path gets run enough times, then frankly, it simply doesn’t matter, they could have been written in bash and still be “fast enough”.

Like, I can’t fathom a program that doesn’t have loops where the actually important part happens. You simply can’t write enough “linear” code to make a modern CPU sweat even just a little. And if you do have said loop, than it will be JIT compiled.

Re:Java 18 / JDK 18: General Availability by pkolaczk on Wednesday March 23, 2022 @02:57PM (#30781955)
But it's not just interpreting linear code. It is also classloading which involves a non-trivial amount of work before any code in a class can even run. Also I never said the testing code doesn't have any loops. There often are loops but they need to run for a really long time until hotspot kicks in. So if you lose a few tens of millisecond here and there in a single test, you will get minutes or hours in total in a codebase that has hundreds of thousands tests. And it gets terribly worse if many of your tests are end-to-end tests that e.g. launch new JVMs.
Re:Java 18 / JDK 18: General Availability by badhombres on Tuesday March 22, 2022 @11:16AM (#30767078)
It's a stable and well proven technology that still has a lot of developer activity. Businesses are trying to make money, not explore technology, so a lot of them don't want to bother risking deliverables on something they may not have experience with.

IMO

Re:Java 18 / JDK 18: General Availability by paskozdilar on Tuesday March 22, 2022 @11:32AM (#30767324)
IMHO, Marketing.

Java had so many marketing crazes that it's crazy. I still remember the "Java mobile game" fad from a dozen of years ago - Java this, Java that, Java for phone, Java for toaster...

At some point, the public mind starts to associate "programming" with Java. Since there were (and probably always will be, unless we evolve into utopia) hordes of job-desperate people who would do anything to feed themselves and their families, a lot of them hear about Java, start programming in Java and develop their whole world around Java. Java helps them with this by providing this huge, Java-centric ecosystem which gives you everything you ever need to do whatever you want to do.

Of course, there is also the fact that Java is a managed environment and makes it a lot harder for programmers to write broken code, which makes large-scale programming possible even if all you have is a horde of mediocre programmers. But then again, that property is not unique to Java.

Re:Java 18 / JDK 18: General Availability by jbreckmckye on Tuesday March 22, 2022 @12:06PM (#30767789)
I see this post is getting some downvotes; I'm not sure I agree with all of it myself. But I would ask those, who reject the premise here outright, to think back really hard to how things were in the 1990s. The Java brand was everywhere. It was a truly massive endeavour and one of the first languages to really go "viral" as the Solution For Everything.

People laugh at the cute "Java runs on four billion devices!" tagline but back in 1995 if you weren't doing Java, you were a last-century coder. It was so pervasive Brendan Eich even renamed his strange scheme-smalltalk mashup "JavaScript".

Re:Java 18 / JDK 18: General Availability by BrendanEich on Wednesday March 23, 2022 @02:30AM (#30775603)
I didn't name JS, Netscape management and marketing did the trademark deal with Sun to base its name on Java, which was truly hyped and heralded.

(Also, Scheme-Self, not Scheme-Smalltalk.)

Re:Java 18 / JDK 18: General Availability by twic on Tuesday March 22, 2022 @12:44PM (#30768370)
There absolutely was massive Java hype.

Twenty-five years ago

Hype is not reason why "a major Silicon Valley company that's migrating their backend to it".

Re:Java 18 / JDK 18: General Availability by jbreckmckye on Tuesday March 22, 2022 @12:57PM (#30768559)
No, but I think it's a big contributor to the network effect advantage Java has.

I'm not bashing the language - it certainly has its defenders. Some people regard simplicity as a virtue (although I'd question how simple Java is nowadays). But I think even ardent Java fans will concede, Java has some deficiencies as a language. The main reason people use Java, is that people know Java. And the main reason they know Java, is because it is used.

It takes a long time to kill a network effect.

Re:Java 18 / JDK 18: General Availability by paskozdilar on Tuesday March 22, 2022 @12:27PM (#30768123)
People don't like to see their favorite languages bashed. It's completely understandable.

I suppose there are many Java enthusiasts on here.

Re:Java 18 / JDK 18: General Availability by kaba0 on Tuesday March 22, 2022 @04:28PM (#30771084)
I mean, Java is not a liked language by any metrics, so I guess fans (myself included) are more than used to bashing. That’s why I don’t think that marketing helped the language become as great as it is. Sure, it had a part, but if something would have been substantially better it could have taken over a long time since java is not hypes at all anymore.
Re:Java 18 / JDK 18: General Availability by paskozdilar on Tuesday March 22, 2022 @06:21PM (#30772362)
> but if something would have been substantially better it could have taken over a long time

I don't think that is true. Windows is still around.

Re:Java 18 / JDK 18: General Availability by criddell on Tuesday March 22, 2022 @01:20PM (#30768846)
The marketing was pretty nuts. One of the consequences was Netscape deciding to name their scripting language JavaScript.
Re:Java 18 / JDK 18: General Availability by stonemetal12 on Tuesday March 22, 2022 @11:54AM (#30767602)
What else would you use? Java is the shark that ate everyone else's lunch. At this point all you have as alternatives in the category of "easy to use for backend type stuff" is C#, and go. Both of which have their pros and cons but on the whole aren't bad choices. I guess like bellbottoms, Java is making a fashionable comeback.
Re:Java 18 / JDK 18: General Availability by jillesvangurp on Tuesday March 22, 2022 @12:41PM (#30768325)
Kotlin is actually the natural upgrade from Java if you want something that feels more modern than Java. Very easy to switch to from Java: a conversion tool is actually built into intellij.

For most traditional Java frameworks (like Spring or Quarkus), Kotlin has long been a first class citizen (support, documentation, custom Kotlin extension functions, etc.) and probably the easier language to use when you are starting out with those frameworks. And of course on Android, it has long replaced Java as the default language.

On the server server-side, Spring has done so much work on integrating with Kotlin in the last five years that you are probably not doing yourself any favors if you choose not to use that. Kotlin DSL support is just a killer feature here. Spring has really embraced that and they've added nice Kotlin DSLs for pretty much everything that matters. No more builders. No more endless function chaining. No more annotation magic (or at least a lot less of it).

Re:Java 18 / JDK 18: General Availability by zls on Tuesday March 22, 2022 @03:30PM (#30770401)
I'd been eagerly following Kotlin since it was announced in the early 2010s, and could hardly contain myself when I finally got to try it out in real life about a year ago. But... honestly, in 2021, it was underwhelming.

- Compiler performance, especially of mixed Java/Kotlin compilation, is spotty.

- Support and tooling maturity is way behind Java. I'm trying to use it with Bazel, but the support lags far behind the Java equivalents.

- Interop with Java libraries that use annotations or interfaces is maddening.

- Perhaps a matter of taste, but the `var` keyword is a blight, even in Java.

- for all the complaints about "== vs .equals" and that sort of thing, these are by now incredibly well understood pitfalls that are generally checked by static analysis, sometimes even at compile time now by e.g. ErrorProne

In the early days, when it seemed like Java development might stall because of legal hell, Kotlin was a breath of fresh air. But today now, Java is clearly on a path to cannibalize Kotlin's most valuable features. Record classes and pattern matching obviate the biggest draws of Kotlin, while maintaining the buttoned-up, no-fun-but-extremely-pragmatic rigor of the Java language.

Once the glow started to fade, I was left with a very boring, familiar question: what am I really gaining by using this new tool? Is it worth the cost? and on my list of problems I deal with daily as a Java developer, the problems addressed by Kotlin are now so far down on the list that it's not worth dealing with even the tooling friction imo. For me, anyways.

Re:Java 18 / JDK 18: General Availability by kaba0 on Tuesday March 22, 2022 @12:46PM (#30768397)
But Kotlin will never be first class citizen on the JVM itself. Also, I feel like kotlin is falling in-between all the platforms it try to handle (android, native, js), which might not be a good thing to do.
Re:Java 18 / JDK 18: General Availability by pjmlp on Tuesday March 22, 2022 @12:58PM (#30768574)
Currently set at 8% of Java languages.

https://www.infoq.com/news/2022/03/jrebel-report-2022

Hardly a successor of anything outside Google's ecosystem.

Re:Java 18 / JDK 18: General Availability by jillesvangurp on Tuesday March 22, 2022 @02:53PM (#30769966)
Those statistics are a bit misleading because there is a lot of legacy Java code out there.

You can see that in the statistics for Java 8 in the link you provided. 37% is still stuck on Java 8. That's quite old. We're talking about projects that have not updated anything in close to ten years. And some even use older versions than that apparently.

That's not because those versions were that good but because some people just are that conservative. Java was always popular with conservative companies like banks. Companies like that are likely not using anything released in the last six years. According to Jrebel, that's about half of the survey. You can read into that what you want. But it's kind of meaningless for new projects.

Kotlin had their 1.0 release only six years ago. Spring boot 2.0 followed two years later and that was the first version to incorporate a lot of Kotlin and add explicit support for it.

It would be more interesting to get some statistics for Spring Boot 2 projects and Kotlin usage. Or even break them down by point release (2.7 is coming out soon) and there should be a version 3 by november as well. I'd expect a jump in Kotlin users with each of those point releases. JDK 17 / Kotlin 1.6 are going to be the minimum supported version for v3.

So, the percentage of users of anything over java 12 vs kotlin users is kind of suggestive: 12% vs 8%. Modern Java seems to be not that much more popular than Kotlin. And of course there's a difference between people that have upgraded their JVM and those that are actually actively using the new language features in Java.

Re:Java 18 / JDK 18: General Availability by pjmlp on Tuesday March 22, 2022 @03:02PM (#30770078)
Kotlin can target Java 8 JVMs, yet hardly anyone adopts it in a meaningful way without papa Google forcing it.

It would also be interesting to compare those Spring Kotlin numbers against the versions back when Spring was equally motivated to support Scala and Groovy a decade ago.

In any case it hardly matters when the platform only supports Java out of the box on the JDK, without extra tooling, and anything besides InteliJ is a second class experience.

Re:Java 18 / JDK 18: General Availability by jillesvangurp on Wednesday March 23, 2022 @04:43AM (#30776362)
Technically yes, but most users would run something more modern. It does not make sense to use Kotlin and then be conservative with the JVM runtime.

Intellij is written in Kotlin. It does Kotlin really well. Better than Java even.

Re:Java 18 / JDK 18: General Availability by pjmlp on Wednesday March 23, 2022 @12:45PM (#30780424)
It isn't what Android devs say, always complaining about compilation times, IDE freeze ups with.

InteliJ is partially written in Kotlin, unless they decided to port everything on top of Kotlin/Native.

As for why Kotlin exists at all,

> And while the development tools for Kotlin itself are going to be free and open-source, the support for the enterprise development frameworks and tools will remain part of IntelliJ IDEA Ultimate, the commercial version of the IDE. And of course the framework support will be fully integrated with Kotlin.

https://blog.jetbrains.com/kotlin/2011/08/why-jetbrains-need...

Re:Java 18 / JDK 18: General Availability by tetsusaiga on Tuesday March 22, 2022 @12:13PM (#30767894)
This is my default answer. What else would you use? C# is the only realistic alternative in my opinion, and I could respect that choice.

I work in Go currently and although I see the positives, I'd be less inclined to unleash a bunch of mid-level devs using Go to create a huge codebase.

If I could have my way, personally, I'd go for one of the other fun JVM langs out there... but that's just me having fun.

Re:Java 18 / JDK 18: General Availability by Ternari on Tuesday March 22, 2022 @03:52PM (#30770654)
> I'd be less inclined to unleash a bunch of mid-level devs using Go to create a huge codebase

Why?

Re:Java 18 / JDK 18: General Availability by l5ymep on Tuesday March 22, 2022 @11:18AM (#30767123)
Java developers are cheap and easy to find. There are libraries for everything that you would need - AWS SDK, Redis, etc. Performance is tolerable and can be improved with things like Micronaut and native ahead of time compilation (GraalVM).
Re:Java 18 / JDK 18: General Availability by sz4kerto on Tuesday March 22, 2022 @11:19AM (#30767140)
They're not cheap :) or -- I'm not sure what you mean by cheap, but good Java coders are generally amongst the best paid ones.
Re:Java 18 / JDK 18: General Availability by isbvhodnvemrwvn on Tuesday March 22, 2022 @12:03PM (#30767740)
Good <insert any language> coders are generally amongst the best paid ones, but let's be honest an average Java developer is lost if they can't find an annotation to solve their problem. It was the "default mid-tier university language" for a while, and it really shows in quality of people who apply.
Re:Java 18 / JDK 18: General Availability by paulmd on Tuesday March 22, 2022 @11:35AM (#30767367)
it's really bimodal imo, there's a tier of sweatshop contractor job that pays $50-70k (or did before salaries got nuts the last few years) and then senior jobs pay $140k ish average now. Senior getting paid more isn't new but it seems like maybe a 2x ratio is higher than elsewhere.
Re:Java 18 / JDK 18: General Availability by manuelabeledo on Tuesday March 22, 2022 @11:22AM (#30767178)
> Java developers are cheap and easy to find.

I wish.

Re:Java 18 / JDK 18: General Availability by wiseowise on Tuesday March 22, 2022 @04:43PM (#30771258)
Nobody said they’re good quality though.
Re:Java 18 / JDK 18: General Availability by throw_m239339 on Tuesday March 22, 2022 @03:28PM (#30770368)
> Java developers are cheap and easy to find

As opposed to what developers that aren't cheap? Node.js? PHP? C#? Python? I have no idea what developer you're talking about here. Do you think JEE developers are cheap?

Re:Java 18 / JDK 18: General Availability by kaba0 on Tuesday March 22, 2022 @12:52PM (#30768477)
Native AOT doesn’t improve performance, but start up time and memory overhead.
Re:Java 18 / JDK 18: General Availability by letmeiiin on Tuesday March 22, 2022 @11:24AM (#30767200)
Because Java is engineered. You can imagine the amount of work going into it. You have multiple companies have whole teams working just on different garbage collection algorithms. No other dev stack has this kind of focus. The JVM is a small wonder. And Java is evolving quite nicely too.
Re:Java 18 / JDK 18: General Availability by renewiltord on Tuesday March 22, 2022 @11:26AM (#30767224)
Using backend technology:

- Java has great ecosystem support

- JVM is very performant

- Java has well understood quirks

- Reasonably mature build system

- Good deploy story

I wouldn’t use Java for a web server but I like it very much for many other things.

I think Scala + Play does a good job for JVM web frameworks but I’d use a Typescript thing (or just Rails)

There are downsides to Java. Bit and byte manipulation are annoying, for instance. But I’m still happy with it.

Re:Java 18 / JDK 18: General Availability by WYepQ4dNnG on Tuesday March 22, 2022 @12:03PM (#30767731)
JVM echo system / tools / libraries / performance is awesome. Frameworks like Spring/Spring Boot have made JVM the default choice for many big tech. It is a no brainer and it works. No one will ever get fired for choosing Spring Boot for a new project :)
Re:Java 18 / JDK 18: General Availability by rr808 on Tuesday March 22, 2022 @11:32AM (#30767319)
Its popular because it was popular. C#/Go/Rust/Scala/Kotlin have some advantages over Java but aren't worth switching because Java works fine. Java has been around a long time and lots of people know it.
Re:Java 18 / JDK 18: General Availability by matwood on Tuesday March 22, 2022 @11:21AM (#30767173)
Great tooling. Good performance. The JVM is very tunable. Huge ecosystem of libraries. Language wise modern Java is fine, but if not, there are other languages on the JVM that interop.
Re:Java 18 / JDK 18: General Availability by vorpalhex on Tuesday March 22, 2022 @11:16AM (#30767087)
With Java comes the whole JVM which is equal parts blessing and curse. You no longer need to know a bunch of OS details, but you pay in overhead.

From a business standpoint, there are lots and lots of Java programmers out there. Of course that doesn't reflect anything about the average skill of those programmers..

Re:Java 18 / JDK 18: General Availability by kaba0 on Tuesday March 22, 2022 @12:50PM (#30768440)
For a typical business app, I really don’t think there is all that much overhead. Java is very fast, virtual calls are basically free due to the JIT, and these apps usually don’t need that much cache coherency for issuing an SQL query for a request. It’s not decoding video.
Re:Java 18 / JDK 18: General Availability by vorpalhex on Tuesday March 22, 2022 @01:43PM (#30769125)
If you think 512mb of base memory usage is "nothing" and you're ok with slow program start times, that's probably fine.

If you're like me and you sort of get sad when your program uses more than 64mb when idle because it feels wasteful, then yeah that overhead is pretty gnarly.

"But we have servers with hundreds of gigs of ram!" you might respond - and sure, we do, but having resources doesn't mean you have to use them. It is better to write small fast efficient programs than extravagant enterprise stuff.

Re:Java 18 / JDK 18: General Availability by kaba0 on Tuesday March 22, 2022 @02:30PM (#30769664)
What about the fact that Java is the most energy efficient managed language? Not constantly crunching through memory to choose which memory should be freed is efficiency, not laziness/bloat.

Sure, there are use cases where it is not a reasonable tradeoff, but for CRUD business apps, it is perfectly fine. Especially given that not all cores can be used uniformly.

Re:Java 18 / JDK 18: General Availability by igouy on Wednesday March 23, 2022 @01:42PM (#30781147)
Maybe `vorpalhex` was interested in any "most energy efficient" language, not just a "managed language".
Re:Java 18 / JDK 18: General Availability by cies on Tuesday March 22, 2022 @11:16AM (#30767083)
Tooling is quite good with IntelliJ and Gradle, Kotlin is neat. It's pretty fast, allows for high level'ish programming and is verrrry widely used (many like to claim this helps for finding devs, seen by many others as the super scarcest thing producing software, but i beg to differ).
Re:Java 18 / JDK 18: General Availability by stjohnswarts on Tuesday March 22, 2022 @12:34PM (#30768232)
First comer advantage. Initial Java was a robust, yet simple, sane build tools, relatively safe, typed language when most everything else was c or c++ and not as "safe" (modern c++ is actually very safe language if you stick to its guidelines however). Over time Java has become almost as complicated as Modern C++ but people picked it up over time mostly. It's still used because it's still a robust general purpose language, tons of libraries, huge corps don't like to rewrite things, and there are lots of Java programmers out there. Don't let the webstack blind you, there is a whole other world out there of backend, embedded, finance, and legacy stuff that hackernews audience is just a small part of.
Re:Java 18 / JDK 18: General Availability by gmokki on Tuesday March 22, 2022 @01:26PM (#30768932)
One thing that is not mentioned is security. There are java libraries for almost everything. And when something is implemented in Java it is much harder to exploit.

Python and node are both great but mostly just wrap C libraries, so If openssl or your database driver has a bug your fancy interpreted/sandboxed language does not help.

Java has existed a long time and developers have had time to reimplement many popular protocols and libraries. This can sometimes cause few % points of performance, but you get stability and the excellent monitoring&debugging.

For example, if I need to accept images from the internet I would use Java since there are pure java image libraries that cannot be exploited with unexpected data. At most it fails and everything is cleaned up.

Re:Java 18 / JDK 18: General Availability by tauntz on Tuesday March 22, 2022 @11:21AM (#30767163)
It's rather easy to use, stable, has a really decent standard library, the tooling is excellent, it's performant, etc.

There are 3rd party libraries and integrations for _everything_ and it's comparatively easy to find skilled developers with years of experience.

Re:Java 18 / JDK 18: General Availability by oaiey on Tuesday March 22, 2022 @11:44AM (#30767485)
This is an interesting question. Not because of Java (that is answered) but because of the alternatives. Kotlin/Scala/C#/F# are the same stack types, C/C++/Rust are lower level, leaving it realistically (job market) to Python, JavaScript and Go. Python and JavaScript are quickly sorted out as non static typed and Go is still not in the league of Java or .NET despite all it's amaziness.

So it boils down to: do the people like static typing or not.

Re:Java 18 / JDK 18: General Availability by darkhorn on Tuesday March 22, 2022 @07:21PM (#30772896)
Re:Java 18 / JDK 18: General Availability by jwesleyharding on Tuesday March 22, 2022 @11:31AM (#30767297)
1) network effects, around runtime and core library especially. IMO, for enterprise, runtime is especially sticky. 2) of the JVM languages, Java will (always?) be the easiest to hire for
Re:Java 18 / JDK 18: General Availability by manigandham on Tuesday March 22, 2022 @01:05PM (#30768669)
Java (and .NET) have vast ecosystems with lots of developer experience, a massive standard library, a big selection of 3rd-party packages, vendors and services, solid backwards compatibility and deployment stability, and tons of research/development constantly making everything better.

Contrary to the Silicon Valley popular opinion, these languages are incredibly productive and run much of the world, with code running in all of the Fortune 500 companies down to small businesses and even your phones.

Re:Java 18 / JDK 18: General Availability by cityofdelusion on Tuesday March 22, 2022 @11:17AM (#30767093)
It’s stable, mature, fast, and it is very easy and cheap to hire for, both domestic and offshore.
Re:Java 18 / JDK 18: General Availability by Banana699 on Tuesday March 22, 2022 @04:29PM (#30771086)
It's popular for the same reason C++ and JS are popular, hype trains and lock-in. There's no good reason to use it in a new project, people saying "Performance" and "Tooling" need to take a good long fresh look at the language landscape, we're not in 2005.

A trivially easy replacement would be Kotlin, it compiles to the same VM (and additionally webassembly), it is designed and implemented by one of the leading IDE vendors, it can trivially call and be called from Java, it has tons of zero-cost syntactic sugar that covers the inhumane verbosity that Java buries you under till your eyes bleed and your hands scream. A well-designed language, what should have been all along.

Re:Java 18 / JDK 18: General Availability by vips7L on Tuesday March 22, 2022 @11:43AM (#30767465)
Tooling, performance, observability, and maintainability.
Re:Java 18 / JDK 18: General Availability by sidlls on Tuesday March 22, 2022 @11:17AM (#30767098)
It's trivial to find dirt-cheap java programmers domestically and in overseas sweatshops.