Confused about JRE and JDK and latest Java versions - java

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

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

Related

How do I get Java FX running with OpenJDK 8 on Ubuntu 18.04.2 LTS?

When trying to compile an JavaFX application in the environment:
java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"
I get the error-message:
cannot access javafx.event.EventHandler
[ERROR] class file for javafx.event.EventHandler not found
I tried to find a solution by following these links:
how to add javafx dependencies in maven with java 10
https://mvnrepository.com/artifact/org.openjfx/javafx/11
Maven project with JavaFX (with jar file in `lib`)
https://github.com/javafx-maven-plugin/javafx-maven-plugin
https://askubuntu.com/questions/1091157/javafx-missing-ubuntu-18-04
https://unix.stackexchange.com/questions/505628/add-openjfx-class-path-in-debian-for-java11
https://askubuntu.com/questions/609951/javafx-is-not-on-the-default-classpath-even-with-oracle-jdk-1-8
Why is JavaFX is not included in OpenJDK 8 on Ubuntu Wily (15.10)?
http://can4eve.bitplan.com/index.php/JavaFX
The most promising actions where to
install openjfx with apt install openjfx
set the JAVA_HOME environment variable to /usr/lib/jvm/java-8-openjdk-amd64
But the error persists.
What needs to be done to get OpenJDK 8 and JavaFX working on Ubuntu 18.04.2 LTS?
The hint from
https://github.com/JabRef/help.jabref.org/issues/204
helped. The commands:
apt purge openjfx
apt install openjfx=8u161-b12-1ubuntu2 libopenjfx-jni=8u161-b12-1ubuntu2 libopenjfx-java=8u161-b12-1ubuntu2
apt-mark hold openjfx libopenjfx-jni libopenjfx-java
fixed the problem. Many thanks to https://github.com/Druidefix for this. (If you'd like to answer this yourself I'll happily delete my own answer ...)
What I did was build it from source. The instructions here on the OpenJDK wiki worked for me. Once I built it, I had to put the jars in the right place, like this other stackoverflow post talked about.
cd build/sdk/
sudo cp -R rt/lib /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/
sudo cp ./lib/ant-javafx.jar /usr/lib/jvm/java-8-openjdk-amd64/lib/
sudo cp ./lib/javafx-mx.jar /usr/lib/jvm/java-8-openjdk-amd64/lib/
After that I was able to compile my project!
Use Oracle JDK (even if only as a temporary workaround)
For any learners looking for a bit of basic practice with javafx, installing Oracle's Java 8 (which has javafx built-in) might be a better solution then messing about with open packages. There are great instructions here
You can continue efforts getting openjfx installed, but this will keep your learning going.
This has already been suggested by aran in a comment to the OP, please consider upvoting that comment.

How to install openJdk 8 in windows 64 bit os

I need to install open JDK in my Windows 64-bit os. I have used ORACLE open JDK and downloaded from the below link: https://jdk.java.net/8/
While downloading I have selected Accept License Agreement and installed.
But, after the installation when I tried checking the version using command java -version it's showing like regular JDK.
Can anyone help me to get where I went wrong? Or is there any better vendor to install open JDK in windows. Thanks.
Amazon offers an open jdk for Windows (and other OS), but just for Java 8, 11 and 16.
You can download it from here: https://aws.amazon.com/es/corretto/
After installing it and running the java -version command, you will see something like this:
>java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment Corretto-8.242.08.1 (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM Corretto-8.242.08.1 (build 25.242-b08, mixed mode)
You need to set your java version in environment of you machine and target your JDK8 bin folder, or any JDK that you want to have at your disposal when you run java -version.
The best way to do this is to use the builds from adoptopenjdk. They're very high quality and come in multiple variants for Windows ranging from zip files to MSI installers. Dead simple to install JDK 8, 11 or 15.
But, after the installation when I tried checking the version using command java -version it's showing like regular JDK.
This is because JAVA_HOME is pointing to your old JDK. You need to go to Control Panel and change the Environment Variables. Just do a search on Windows 10 for "Environment Variables" to easily find that configuration panel.
Azul Systems provides builds of OpenJDK and relative installers, for all OSes and JDK versions.
It also provides builds of the JDK with OpenJFX included.
The installers bind JAR files to be executed by Java on Windows.
Download from azul.com website
I know this is old but should anyone run across this in search of OpenJDK 8 go here
https://developers.redhat.com/products/openjdk/download

Will scala work with JDK 1.10

The scala download page says that you have to have JDK 1.8 installed. It doesn't say anything about newer versions of the JDK.
Does scala work with JDK 1.10?
A page was recently added to the official Scala website outlining the compatibility of Scala versions with different JDK versions: https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html
In short: JDK 8 is recommended. However compiling and running recent Scala versions should work on JDK 9 and 10, but I wouldn't rule out the possibility of encountering some corner cases.
The JDK has a fairly good track record of backwards compatibility.
Unfortunately, there are always some things that change. Even from minor version to minor version you can find something broken.
I can guarantee there will be something that doesn't work, but in general most of the core features will. Still, I would never trust any change on production until you've tested it thoroughly.
Look forward to doing such testing every 6 months now.
I encountered the similar issue. On Ubuntu 16.04 I had installed JDK 10 and then installed scala 2.11.6.
Using IntelliJ IDE I was able to make them work together however in terminal when typing
$ scala
I got just
Exception in thread "main" java.lang.NoClassDefFoundError: javax/script/Compilable
The solution was to install also JDK 8 and set it to be used by default, that is:
$ sudo apt-get install openjdk-8-jdk
$ sudo apt-get install openjdk-8-jre
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
and to choose JDK 8. After that, everything is fine :)
$ scala
Welcome to Scala version 2.11.6 (OpenJDK 64-Bit Server VM, Java 1.8.0_181).
Type in expressions to have them evaluated.
Type :help for more information.
scala>

Eclipse cannot see java.time library on ubuntu 14.04

currently, I have a java project, at first I started my project on windows however now I had to switch ubuntu 14.04 (Dont worry, I dont have any OS dependent part on my project). Unfortunatelly, eclipse on ubuntu cannot see libraries starting with jave.time. For example
import java.time.LocalDateTime;
import java.time.LocalTime;
in these lines it is written that The import java.time cannot be resolved (Other libraries are succesfully detected)
As far as I saw on the web, I had to install JDK 8 for using time library I guess. However, I dont know how to do that in ubuntu [this is my first time for ubuntu]
Let me explain what I did so far, I installed JDK with the following commands
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
[By the way I wanted to install Oracle Java but instead these commands installed Open JDK]
Now output of java -version command is :
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~trusty1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
When I look at the eclipse->help->installation details
java.runtime.version=1.7.0_75-b13
java.specification.name=Java Platform API Specification
java.specification.vendor=Oracle Corporation
java.specification.version=1.7
So, How could I solve my problem ? But as I said at the beginning of my question, this is my first time with ubuntu so while explaining could you also provide necessary commands?
Taken from the repository guide try run this command.
sudo apt-get install oracle-java8-set-default
After that, try to restart your eclipse.
The problem is, as described as Jon and Tim, is because your environment is still using the java version 7.
In your eclipse, open the preferences page
then, go to the installed jre option under java tree
from there, click the add button, choose Standard VM and then add the installed java 8 jdk home folder and click finish.
check the check box and then try build your project again.
Even though you have installed the Java 8 JDK (the correct version to use for java.time, q.v. Jon Skeet's answer), you still need to tell Eclipse to point to this JDK.
Open the eclipse.ini file and search for lines which look like the following:
-vm
C:\Java\JDK\1.6\bin\javaw.exe
Then replace that path with the correct path to your JDK 8. You will also need to restart your IDE.
As a quick check to see if Eclipse be using the JDK 8, you can import java.time.* at the top of one your classes and see whether you get errors.

I had Open JDK 1.7 on CentOS; I installed Oracle's Java rpm; Oracle Java doesn't seem to exist

I started off with CentOS and OpenJDK 1.7
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
In order to run a specific application, I want to use Oracle's Java 1.6, provided from an RPM.
I copied the Oracle binary to a specific new directory:
# pwd
/oracleJava/jdk-6u45-linux-x64-rpm
I extracted the binary and it gave me the following files:
# ls
jdk-6u45-linux-amd64.rpm
sun-javadb-core-10.6.2-1.1.i386.rpm sun-javadb-javadoc-10.6.2-1.1.i386.rpm
sun-javadb-client-10.6.2-1.1.i386.rpm sun-javadb-demo-10.6.2-1.1.i386.rpm
sun-javadb-common-10.6.2-1.1.i386.rpm sun-javadb-docs-10.6.2-1.1.i386.rpm
I installed the RPM and the rpm utility believes that it installed properly:
rpm -q jdk
jdk-1.6.0_45-fcs.x86_64
# rpm -Uvh ./*.rpm
Preparing... ########################################### [100%]
package jdk-2000:1.6.0_45-fcs.x86_64 is already installed
# rpm -Uvh sun-javadb-*.rpm
[I omit the feedback because it generates a formatting error]
#
However, the Java version just shows 1.7
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
In other words, I was expecting the Oracle files to give me some new /java directory somewhere, with a new java executable that would return a different answer for "java -version"
I need that new directory so that I can set JAVA_HOME and use the 1.6 version of Java.
Helpful suggestions would be greatly appreciated. Thanks in advance.
The Oracle JDK RPMs are horrible.
They do not register with the alternatives system.
They do not Provide (in RPM terms) "java"
They have messed up their RPM 'version string' and rely on Epoch (...)
All versions of the JDK (i.e. 1.6 vs 1.7) have the same Epoch
In order to quickly remedy your problem you can run the following:
/usr/sbin/alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000
It will register and prefer the Oracle java installation as an alternative. OpenJDK has weight 16000; here we register with 20000. Once you've run this command you can switch between java versions by using the (already mentioned) alternatives --config java command.
As for a less quick fix you can use my virtual java package. It's quite possibly not perfect (I'm open for improvements ;) ), but it Provides java (making my apache-tomcat package happy) and registers with the alternatives system. This virtual package simply depends on jdk...you can find it here: https://github.com/keystep/virtual-java-rpm
Run the following command to see if your JVM is getting listed.
sudo update-alternatives --config java
If your JVM gets listed select it.
The problem is that Oracle's RPMs are (wilfully IMO!) ignorant of the "alternatives" system.
Instead, they install stuff in a non-standard place (/usr/java) and then expect the user / system administrator to mess with the PATH variable ... by hand.
It is a nuisance!
So what has probably happened in your case is that your JDK / JRE has been installed in a subdirectory of /usr/java ... but since you haven't added the relevant bin subdirectory to the front of your PATH you are still picking up the OpenJDK tools via the java command name.
You can fix this after the fact by using "alternatives" to configure and then select the Oracle commands. But it is messy, especially if you want the JDK tools as well. (There are a lot of them!)
Please check that whether your JAVA_HOME points to JDK 6 using echo $JAVA_HOME. In order change your JAVA_VERSION to Java 6, you need to point to the Java development KIT 6. You also need to add the bin directory to the $PATH variable. Please ensure that JDK6 bin directory comes in the $PATH prior to other JDK bin,if any. You can check the version of your Java in the environment by command java -version.The other answer by learningloop is very perfect to switch between different Java configurations
Try to the following method
delete OpenJDK folder from
/usr/lib/jvm
I had same problem and got solution through this method

Categories