I'm just starting to use Java. I've been following the instructions in the answer to this question in order to compile and run my first Java program. I have just installed JDK 11 and have set the path to C:\Program Files\Java\jdk-11\bin
. Having done that, I've been able to compile my program using the following command:
javac HelloWorld.java
(The file is called HelloWorld.java
.)
As a result of this a file called HelloWorld.class
appears in the directory. Now I've tried to run the program using this command:
java HelloWorld
This doesn't work. I get the following output:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
I have looked at this question, which combined with the error message I'm getting suggests to me that whatever Java is running my program is meant for older-version files than my compiler is churning out.
Following the advice of the answer to the above question, I have tried running javac -target 8 HelloWorld.java
. However, this doesn't work either. I get the following warning:
warning: target release 8 conflicts with default source release 11
and no HelloWorld.class
gets created.
I have a feeling I need to have Java Runtime Environment 11, but I don't know how you get it. Searching queries like "get JRE 11" sends me back to the main Java download page, which is offering "version 8".
Appendix: the directory I'm keeping HelloWorld.java
in is called java
, if that makes any difference.