0

I'm new to Java and are trying to run my first Java file. I can't get it to run.

When I go into cmd and type "javac MyFile.java" it creates a MyFile.class file next to it and when I try to run the file with "java MyFile" I get an error message: "MyFile has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 52.0".

I have tried to look for a solution on both stackoverflow and google and couldn't find a solution I understood. I think I have figured out that I need to have something called Java 12, and I currently have Java 8. When I search for Java 12 on google I can't find anything else than Java 8 (maybe I'm blind, but I can't find it). I have found Java JDK 12.0.2 but I also have that installed and it doesnt seem to work either so I guess its not the same as Java 12. And yes, I have them listed in the system PATH variables.

Where/how can I get Java 12?

(I just want to say again that this is my first time using Java to code so I have no idea how any of this works)

Edit:

java -version (in cmd): "1.8.0_221"

javac -version (in cmd): "12.0.2"

Path variable: "C:\Program Files\Java\jdk-12.0.2\bin"

JAVA_HOME variable: "C:\Program Files\Java\jdk-12.0.2"

NitroFray
  • 43
  • 7
  • 2
    Sounds like you already have Java 12. Check your path to see where `java` and `javac` are pointing. – shmosel Aug 20 '19 at 00:18
  • 2
    https://www.oracle.com/technetwork/java/javase/downloads/index.html has everything you need. It actually sounds like you have 2 different Java versions installed: one for `java`, another for `javac`. –  Aug 20 '19 at 00:18
  • 3
    What is your PATH set to, and what value does JAVA_HOME have? *I have found Java JDK 12.0.2 but I also have that installed and it doesnt seem to work either so I guess its not the same as Java 12* No. JDK 12.0.2 **is** Java 12. – Elliott Frisch Aug 20 '19 at 00:27
  • 2
    In _cmd_ (as you call it), enter the command `where java` and the command output will be the path to the file `java.exe`. Then enter the command `where javac` to get the location of `javac.exe`. The command `javac -version` will tell you the `javac` version and the command `java -version` will tell you the java version. [List of Java class file format major version numbers](https://stackoverflow.com/questions/9170832/list-of-java-class-file-format-major-version-numbers) may be of interest. By the way, I recommend having only one java version installed. – Abra Aug 20 '19 at 00:54
  • @Abra the "java -version" is "1.8.0_221", and the "javac -version" is "12.0.2" – NitroFray Aug 20 '19 at 02:28
  • Did you check the `Path` or the `PATH` variable? Normally, your `PATH` should be much longer. – Henry Aug 20 '19 at 02:59
  • You have at least two versions of java installed, namely 1.8 and 12. Do you require both of them? If not, I suggest you remove the one you don't require. What about the output of the `where` command? I didn't see it. Did you post it? – Abra Aug 20 '19 at 07:44
  • @Henry I checked the Path variable. I can't seem to find a PATH variable. – NitroFray Aug 20 '19 at 10:17
  • @Abra It worked when I removed everything else than the java 12 :) – NitroFray Aug 20 '19 at 10:19

1 Answers1

0

It worked when I uninstalled everything except for the Java jdk-12.0.2. I did not have to change the system variables from what is listed in the actuall post/question.

NitroFray
  • 43
  • 7