0

I've been attempting to compile a small java file via javac but have been getting an error 'class file has wrong version 52.0, should be 49.0'

Upon looking this error up, i've found out that this is occuring because I have a different version of Java and a different version of the compiler.

I'm not entirely well-versed on the difference here but I have the following version of Java on my machine:

Java 7u77
Java 8u65
Java 8u66
Java SE Development Kit 8 Update 66
Java 6 Update 38
Java SE Development Kit 6 Update 38

To me, It looks ot me like I have a same version of Java and SDK(8u66) but am not sure why it's causing the failures.

Doing a -version in cmd, I am seeing a similar version:

c:\ServletDevel>java -version
java version "1.5.0_30"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_30-b03)
Java HotSpot(TM) Client VM (build 1.5.0_30-b03, mixed mode)

c:\ServletDevel>javac -version
javac 1.5.0_30
javac: no source files
Usage: javac <options> <source files>

Is there a chance that I'm using an old version of SDK? Or an older version of Java? The plan is to use the Java 8u66 version

Criel
  • 799
  • 1
  • 11
  • 28
  • 1
    Check your environment path to find out which version of java is referenced. – Raf Nov 23 '15 at 14:27
  • 1
    The java runtime, java.exe, must be found in the `Path` environment variable. Replace that with the path to the latest java version in the bin subdirectory. – Joop Eggen Nov 23 '15 at 14:31
  • 1
    Based on the command output, we know what version of java and javac are being executed, both are "1.5.0_30"...interestingly that is not in the list of versions that the OP said were installed. Did you try compiling and running by providing full paths to the specific versions of java.exe and javac.exe that you wanted? – Anssssss Nov 23 '15 at 14:35

3 Answers3

2

Java class version 52 is Java 8. Class version 49 is java 5. You are getting this error because you are trying to use java 8 class file with javac from java 5

Svetlin Zarev
  • 9,115
  • 3
  • 42
  • 69
1

You are using java 1.5.0_33-bo3.

To use another java you need to update your path pointing to the version of jdk you like most.

Note: If more than one path is pointing to the executables of java the first is taken in to account, so add the path at the beginning, not at the end of existing path.

Davide Lorenzo MARINO
  • 22,769
  • 4
  • 33
  • 48
1

You have different versions of Java installed in your system and your path seem to be pointed to the oldest version of Java.

What you have to do is, set the path such that it find the latest version of Java. Do the following steps:

  1. Right click on my computer and select Properties
  2. From the left menu choose, Advanced system settings
  3. Once the System settings window opened, then click on "Advanced" tab
  4. Under advanced tab, select the "Environment Variables" button which will open different window
  5. In the other window find out "Path" variable from list of System variables
  6. Click on Path variable and select Edit
  7. Append (do not overwrite or delete content of path variable only append using semi-colon as separator) the location of latest JDK in the path variable.
  8. Click Apply and OK and then close the command prompt and re-open it and check the version of java again.

The path should contain the OLD VALUE appended with something like below (depending on location of your JDK):

C:\Program Files\Java\jdk1.8.0_65\bin

Don't forget to put a semi-color (;) before copy/pasting the path of the latest Java's JDK.

See this question Environment variables for java installation for super clear instructions on how to do this.

Community
  • 1
  • 1
Raf
  • 6,620
  • 1
  • 35
  • 54