1

I have installed both jdk 7 and jdk8 in my system. But my java program is compiling version in 1.8 and executing in 1.7. So it is responding UnsupportedClassVersionError. How can i overcome this problem...

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • "Don't do that" basically. Either compile with 1.7, or compile with `-target` to compile for 1.7, or run with 1.8. We can't really tell which of those solutions is most appropriate, as we don't know *why* you're trying to run with 1.7 at the moment. – Jon Skeet Jul 27 '14 at 07:36
  • How can i set path to execute class file with 1.8 from cmd prompt... It is automatically executing with 1.7 as i had mentioned in my question that both 1.7 and 1.8 is installed in my system ??? I have set Path variable of jdk 1.8... – user3854150 Jul 27 '14 at 17:44
  • Well we don't even know what operating system you're using, which makes it hard to help you. Why don't you just uninstall 1.7? – Jon Skeet Jul 27 '14 at 19:02
  • Yeah that is helpful... but please confirm that it is never possible to execute a class file with lesser version that is compiled and generated by higher version. – user3854150 Jul 27 '14 at 19:56
  • You'd have to compile using `-target`, basically. – Jon Skeet Jul 27 '14 at 19:56
  • what is -target. how can i compile using -target. – user3854150 Jul 27 '14 at 20:13
  • It's a command-line option for `javac`. Run `javac -help` for details. – Jon Skeet Jul 27 '14 at 20:19
  • Please explain in detail how to use javac -target command. – user3854150 Jul 27 '14 at 20:29
  • No. You really need to be able to do some research for yourself. You can't expect to be spoonfed every single detail of everything. Look up the documentation for `javac`, search on the web... there are *lots* of places to find more information. – Jon Skeet Jul 27 '14 at 20:30
  • okk.. thanx allot for your help... – user3854150 Jul 27 '14 at 20:36

4 Answers4

2

Run your code with jdk8 or compile it with jdk1.7.

Jens
  • 67,715
  • 15
  • 98
  • 113
1

How to solve this following error.

 1) Find out due to which jar or class file this UnSupportedClassVersionError is coming?

    2) Try to compile source code of that jar with the JDK version you are using to run your program, if source is available.

    3) If you don't have source try to find the compatible version of that library.

    4) Increase the JRE version you are using to run your program.

Read more:

Deepanshu J bedi
  • 1,530
  • 1
  • 11
  • 23
0

run in jdk8 and compile with jdk 7 should be OK.Maybe compile with jdk8 and run in jdk7

Mr_xiaoM
  • 23
  • 1
  • 6
0

Do not try to do this.

Java8 is the more recent release than Java7. So there are chances that the code which you are compiling with JDK1.8, the same code may not be executable with JDK1.7 as this may not contain the required libraries or the required functionality which are new to the JDK1.8

For Example, for-each loop, varargs, etc is supported by JDK1.5 versions and onwards. So compiling the source code containing above features and trying to run the program on JDK1.4 or it's prior versions is always going to result in an error, as those JDK versions will not be able to identify such code snippent.

However, Oracle's JVM supports backward compatibility. So you can always compile your code on previous version of JDK's and run it on the recent versions.

Amitesh Rai
  • 866
  • 11
  • 21