Live data from Hacker News

Java 18 / JDK 18: General Availability

mail.openjdk.java.net

121–130 of 304 posts

Re: Java 18 / JDK 18: General Availability

#121
post #105

>JEP400: UTF-8 by Default This changes the default charset of the Java APIs to UTF-8. I read that the Java 8's JVM's internal string representation is UTF-16 [0][1]. Is that still the case after JEP400? [0] https://docs.oracle.com/javase/8/docs/technotes/guides/intl/... [1] http://tutorials.jenkov.com/java/strings.html

no, it's only for IO. It lead to way too much breakage if they changed how the string behaves.

I generally like the idea to use UTF-8 strings, but if they didn't want to break string indexing, the indexing would take O(str.length)...

Re: Java 18 / JDK 18: General Availability

#123
post #49
post #44

Earlier quoted context omitted.

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.

But the problem is that checked exceptions create the same “what color is your function” problem for errors.

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

#124
post #105

>JEP400: UTF-8 by Default This changes the default charset of the Java APIs to UTF-8. I read that the Java 8's JVM's internal string representation is UTF-16 [0][1]. Is that still the case after JEP400? [0] https://docs.oracle.com/javase/8/docs/technotes/guides/intl/... [1] http://tutorials.jenkov.com/java/strings.html

Internally strings will either be UTF-16, or if a string can be represented in LATIN-1 it may use a more compact representation.

JEP400 is about I/O, previous to this change when you create something like a FileWriter without specifying the charset the platform default would be used. For a long time this has been recognized as a common foot gun, hence this change to a default that is more likely to be what the developer actually wants.

Re: Java 18 / JDK 18: General Availability

#125
post #6

Is there a reason to use Oracle's closed-source Java implementation instead of the opensource implementations? Asking as someone who's ignorant about Java. edit: per comments below, Oracle's Java is open-source too these days.

AWS Corretto is a good option - https://aws.amazon.com/corretto/

its fully certified and production ready. And most importantly - official Docker image https://hub.docker.com/_/amazoncorretto

Even oracle JDK does not come with a supported, official image

Re: Java 18 / JDK 18: General Availability

#126
post #16

Earlier quoted context omitted.

Java is great, but here's a surprise: if (str1 == str2) { // oops }

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.

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

#127
post #102
post #49

Earlier quoted context omitted.

But the problem is that checked exceptions create the same “what color is your function” problem for errors.

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.

> 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

#130
post #79
post #61

Meanwhile, still using Java 8 at work

I see this everywhere. What's the excuse in your case?

I think it's a mix of complacency, the change to a LTS model, internal governance, and lack of awareness. The company will only get off their ass once 1.8 no longer receives any updates. Looking at some of the older tickets in the system, this was the case when java 7 was no longer supported (massive influx of migration tickets in '15).
Post reply on HN