3

On a desktop with a dual boot I currently have Java JDK 8 in the Linux (Mint) system

chris@M17A ~ $  sudo apt install default-jdk
...
default-jdk is already the newest version (2:1.8-56ubuntu2).
...
chris@M17A ~ $  java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

But I'm sure that in fact 1.8.0_171 is not the latest version, even of Java 8! If I want to change to 1.11.xxx, which seems to be the latest LTS release (for Oracle non-OpenJDK at least), what should I do? Do I have to manually download something, or use a PPA? How can I be sure my Linux OS is using the version-11 JRE and the version-11 JDK?

I've also never quite understood either about the versioning of the JRE side of things and how this corresponds to the JDK being used. On my Windows machine (W10) I am using a Java 9 JDK but a Java 8 JRE (I think). Is this a bad thing to do?

This question says there is no such thing in Windows as a Java 11 JRE, although there is a Java 11 JDK. Is that a problem in W10? Would it be a bad idea to use an JDK 11 with a JRE 8?

I also simply don't understand why it is not possible read somewhere about the "latest JRE" or "latest stable JRE". These do not appear to be coupled one-to-one with the latest JDK as far as I can make out but I'm having difficulty obtaining clarity about all this.

I also have some difficulty understanding whether I should opt for OpenJDK or the other JDK (they're both Oracle so I don't know how to refer to the non-OpenJDK one... "commercial JDK"?). But unlike the above difficulties there are lots of explanations out there. I am mainly looking for "latest stable release" hopefully with LTS. Seems like "Commercial JDK" version 11 might be the way to go...

mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • 1
    A JDK is a superset of a JRE and their versions match. However, Oracle recently stopped providing JRE-only distributions (afaik). And code compiled with newer versions of Java cannot be executed by older versions of Java. – Slaw Aug 24 '19 at 14:37
  • OK thanks. So you're saying that ANY byte code compiled with Java 9 SDK must then be executed by a JRE which is >= 9? I find this a little difficult to believe. New features introduced into the language (e.g. lamba stuff) could quite conceivably compile to byte code which was legal in an earlier version of the JVM couldn't it? I mean otherwise people would be forced to update all their OSs running JRE 8 to 9/10/11 all the time wouldn't they? Or else developers would be reluctant to publish apps written with 11...! I find my devices almost never complain about non-executable byte code. – mike rodent Aug 24 '19 at 14:55
  • 1
    It's not (directly) about added/removed features. A class file has a version flag and the JVM refuses to execute code compiled by newer versions of Java, throwing an `UnsupportedClassVersionError`. Java only strives for _backwards_ compatibility (meaning Java _N_ compiled code can run on Java >= _N_). That said, there's [cross-compilation](https://stackoverflow.com/questions/43102787/what-is-the-release-flag-in-the-java-9-compiler). – Slaw Aug 24 '19 at 15:06
  • FYI, with the demise of both Java Applets and Java Web Start, there is no more JRE that I know of for the latest versions of Java such as OpenJDK 11, 12, or 13. If you need a Java runtime for a desktop app you are building (such as Swing or JavaFX) you must bundle a JVM within your app using newly available tools. Oracle and the Java community no longer expect end-users to consciously install Java, so no need for JRE. – Basil Bourque Aug 25 '19 at 06:51
  • @Slaw/Basil Bourque Thanks again for these added clarifications. So "no JRE for OpenJDK 11, 12, 13": i.e. these then work perfectly well with, what, JRE 8? What about JRE 7? Could somebody point to a source where these compatibility issues are clarified? Also the other SO question I linked to in the above question says there is no JRE 11 for Windows (OpenJDK) but there **is** one for Linux (see the comment there in brackets). I just wish someone would document all this, as it does seem to be fairly important! – mike rodent Aug 25 '19 at 14:19
  • As I said, the versions between a JDK and JRE match. So JDK _N_ corresponds with JRE _N_, regardless of if there's actually a JRE-only distribution or not. And from [§4.1](https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.1) of the JVMS, "_A Java Virtual Machine implementation which conforms to Java SE N must support **exactly** the major versions of the class file format specified for Java SE N in [Table 4.1-A](https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.1-200-B.2)_". So no, code targeted at JDK 11 would not be supported by JRE 8. – Slaw Aug 25 '19 at 19:41
  • I'd hope there's somewhere more accessible than the JVMS that documents this behavior, but the JVMS (and JLS) are the authorities. Also, the answer to the question you link to mentions distributors other than Oracle may provide JRE-only downloads. For instance, it appears you can get one for Windows [here](https://www.azul.com/downloads/zulu-community/?&os=windows&architecture=x86-64-bit&package=jre). But as Basil said, Java desktop applications are moving towards _embedded JREs_, which means the end user doesn't have to worry about having Java installed. – Slaw Aug 25 '19 at 20:03
  • Thanks much re desktop apps. What about the whole Android environ / Internet of things, etc. then, one wonders? To me this is quite a mystery: obviously there's a world of pros out there (I'm not an IT pro) for whom this is a non-issue. Just wish I could learn more to understand why... – mike rodent Aug 25 '19 at 20:49
  • Android is a separate community, at least to a certain extent. According to [this Wikipedia article](https://en.wikipedia.org/wiki/Comparison_of_Java_and_Android_API), Android doesn't even use a "tradition JVM". As far as I know, the latest Android versions only use (a version of?) Java 8. There are libraries out there who have different releases for Android and "regular Java" (e.g. Guava). Many wide-spread libraries still target Java 8 (even if built on later versions, see cross-compilation) to support projects that have yet to upgrade. As for IoT, I don't have enough knowledge in the area. – Slaw Aug 26 '19 at 04:45

1 Answers1

3

Java 8 is the default JDK (recommanded) for your System.

According to this, you need to add the repository of openjdk using this command:

sudo add-apt-repository ppa:openjdk-r/ppa

After that you need to update you index using

sudo apt-get update

If you want to install jdk 11 you can do:

sudo apt-get install openjdk-11-jdk

[Hint]

default-jdk is the default jdk. This means that, if this is up-to-date, you have the recommanded/default version of a jdk.

Also, openjdk seems to be recommanded for linux

dan1st
  • 12,568
  • 8
  • 34
  • 67
  • Thanks. Please see update... could you please be more explicit about what I have to do? Also I imagine you're right when you say JDK 8 is default, but the latest version appears to be higher than 1.8.0_171: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html: _221, seemingly. Is this simply because the apt archives (or whatever they're called) are slightly out-of-date? – mike rodent Aug 24 '19 at 14:11
  • @mikerodent openjdk-11-jdk is not the repository (see my edit) – dan1st Aug 24 '19 at 14:20
  • Thanks again. Tried again (see my update above): same error. Maybe I should just stick with the default version. Seems odd, though: v8 came out in 2014, v9 in 2017 and v11 a year ago. – mike rodent Aug 24 '19 at 14:34
  • @mikerodent My fault. You have to execute `sudo apt-get update`. – dan1st Aug 24 '19 at 14:36