Live data from Hacker News

Which version of JDK should I use?

whichjdk.com

221–230 of 258 posts

Re: Which version of JDK should I use?

#222
post #50

So for those running Scala in production, which version do you use? I am still seeing a lot of projects on 8. New Scala projects are generally on Corretto 11.

I have no problem running web services on the latest JVM, I just migrated a bunch of http4s apps to Temurin Java 17 based docker images. Scala isn't the issue if you can update to the latest patch version; it's more frameworks with outdated Java libraries doing illegal reflective access that are a problem.

Re: Which version of JDK should I use?

#223

I’ve tried more than once to learn Java I find it very confusing. This website resolves one of the issues. The other issue I have is that most Java tutorials use IntelliJ, or some other IDE, which makes it difficult to figure out what a non IDE workflow actually looks like, some managing dependencies is confusing. I wonder if c# and mono is better in this respect

Forget about this website, just download the most recent OpenJDK version and get at it!

As for IDEs, I do recommend IntelliJ for writing the code, but in case you want to understand what happens behind the scenes, you can compile the source code directly in the terminal with `javac YourClass.java`, or *.java, depending on how many files you have.

It will by default place the resulting files in the current directory with the convention of creating directories for packages. If you had no package keyword in your files it will result in a simple YourClass.class file that you can run with `java YourClass` (do note that you run classes, not the file itself). If you had something like com.example as a package, it will be placed under WORK_DIR/com/example/YourClass.class.

It should be run from the current work_dir though!

The reason for that is the notion of a class-path, analog of the PATH variable of unix systems. It lists the package-aware class files, and defaults to the working dir, meaning it will find com.example.* files from here, but not elsewhere.

Dependencies are just that, they get concatenated to this class path and thus will be included.

EDIT: You can also just issue `java YourClassWithMain.java`, it will compile and run your class in one go

Re: Which version of JDK should I use?

#224

These recommendations are pretty arbitrary and don't even attempt to scratch the surface of what is actually materially different between the JDKs. Don't use Corretto outside of Amazon... why? Don't use Dragonwell because... China bad? Use Red Hat OpenJDK if you're running on Red Hat servers, Microsoft OpenJDK if you're on Azure, SapMachine if you're on SAP, because... the name matches so that's nice? At least they'r…

> Generally go with JDK 11, if you may have to deal with older software then maybe go with 8

That's a good recommendation for library authors, but if you're deploying an application that's regularly maintained, I would recommend using the most recent version -- that's the cheapest, safest way -- and if it isn't, consider an old version (like 11) with one of the LTS offerings, choosing a vendor you trust to support OpenJDK (https://news.ycombinator.com/item?id=28821316).

Of course, new applications should now target 17. It's both the current version and it has LTS.

Re: Which version of JDK should I use?

#226
post #208

Earlier quoted context omitted.

How is it a mess? You have official Oracle JDK build. You have official Oracle OpenJDK build. You have plenty of alternative builds. It's like kernel.org Linux, Debian Linux, Fedora Linux and so on. Does it hurt Linux? I don't think so. All builds should be perfectly compatible between each other. Simplest way is just use Oracle JDK 17. It's LTS, free and official.

It's a mess because for the average joe such as myself it's very confusing and foggy. There's an Oracle jdk whose usage terms need to be deciphered using a lawyer to understand precisely when and how you can use it. So much that the average advice is to not use it. Like if they told you "hey, node.js is cool but don't use the one from those who maintain and develop the code". This would be a huge red flag for any oth…

If you're on linux, use the openjdk build from your distro's official repository. If you're on windows, download the latest openjdk build from oracle (currently https://jdk.java.net/17/), extract somewhere, put /bin folder on path. Optionally set JAVA_HOME env variable to the main folder path. No clue about OSX but it's probably similar to windows.

Ignore oracle jdk, ignore any concept of LTS/not-LTS, that's only for companies with big pockets and specific needs.

People really like to make it sound more complicated than it actually is.

Re: Which version of JDK should I use?

#227
post #183

Earlier quoted context omitted.

> involving some pretty scary reflection stuff for some unexplained reason This is where it always seems to end up. Why do people bend over so far backwards doing reflection that isn't specified?

Because Java, particularly pre-8 Java, sucks so bad if you try to actually write your whole application in it. (I always found this really frustrating when making the argument for Scala. Yes, Scala-the-language is more complex than Java-the-language. But it's not more complex than the pile of reflection magic that anyone who tries to write a nontrivial system in Java actually ends up using).

I try to do everything in plain-old Java, and my code just keeps running release to release.

Re: Which version of JDK should I use?

#228
post #219

Earlier quoted context omitted.

I mean, yes, there were fewer major features, but there were feature releases in those minor updates; there's nothing wrong with having stable software. Are you also one of those people who complain that stable Debian and RHEL releases include old software? Not everyone wants to live on the bleeding edge, and Java was a heavily enterprise ecosystem (for better and worse:]).

And the latest release is no bleeding edge. After eg. “feature freezing” JDK 17 before release, there was no subsequent changes to the codebase, meaning, they found no bugs whatsoever, which did happen beforehand.

Exactly, I don't get it why people think JDK 12-16 are inferior in any way, this is normal software tests in same way as any other JDK version.

The only difference appears after 6 months after release - if you don't want to upgrade (you should) you have to find vendor that will sell you support for given release.

E.g. Azul provides it for 11, 13, 15, 17. Oracle for 11 and 17.

Adoptium provides builds (not LTS) from 11 and 17 branches, where some vendors push their bugfixes. So it is like a semi-LTS, they won't fix your bugs, but if someone fixed a bug it most likely will end up on that branch.

Re: Which version of JDK should I use?

#230

Is there a way to apt-get the new JDK 17 as a package on Ubuntu, instead of piping a shell script from curl or unzipping a tar? Does anybody use package managers on Linux anymore?

I don't like the 'curl -s " https://XXX " | bash' approach much either, but I've given up trying to work around it. With SDKMan switching between JDKs is painless, despite the install method of SDKMan itself being one of those. But it's not just Java. To build our frontend webapp I need NodeJS, and there too some specific version depending on the version of the webapp or just because we've updated. I'd love to be abl…

Personally, i just use containers to manage business applications - which often need a very particular runtime that's tested, verified and signed off on for maximum stability and predictable deployments.

On the other hand, i only use standard packages through apt/yum/apk/whatever for server software, a distinction that's lost too often in my opinion. Everything that the server needs to operate should have automatic (at least security) updates enabled and ideally the configuration should be fully automated through Ansible with something like GitOps and read only access through SSH (with fallback account with write access for special cases) for maximum auditability and being sure that this is less likely to happen: https://dougseven.com/2014/04/17/knightmare-a-devops-caution...

Furthermore, the servers themselves can be viewed as pretty much disposable at that point. A VM gets corrupted? Wipe it, create a new one, run Ansible against it to set up the environment, then just give the node a label in your container orchestration platform of choice and watch as your business software is automatically provisioned on the node, bringing the total capacity of your cluster up once again.

For personal devices with no important credentials, or development boxes which are similarly unimportant, piping random stuff and trying to work around the problems with multiple SDKs is more permissible, however. Seeing as PHP, Ruby, Go, Java, .NET, Python and other technologies aren't always pleasant to work with if you have different projects that need different environments, as humorously pointed out here: https://xkcd.com/1987/

Containers aren't always comfortable to use for local development (especially with OSes like Windows locally, without WSL2, due to problems with bind mounts but perhaps are for components like DBs, Redis, MongoDB etc.), but in certain dev boxes they are also viable, thus making development even easier.

Post reply on HN