1

i have java version "1.6.0_45" and javac 1.7.0_51 when i run my file as javac -source 1.6 Mouse.java then it show error this warning: [options] bootstrap class path not set in conjunction with -source 1.6 1 warning and when i run simple java Mouse then it show error Exception in thread "main" java.lang.UnsupportedClassVersionError: Mouse : Unsupported major.minor version 51.0.

Srb
  • 219
  • 3
  • 13
  • possible duplicate of [Unsupported major.minor version 51.0](http://stackoverflow.com/questions/10382929/unsupported-major-minor-version-51-0) – Scary Wombat May 02 '14 at 06:58

3 Answers3

4

java.lang.UnsupportedClassVersionError: Mouse : Unsupported major.minor version 51.0

That error is caused by incompatible Java versions. You're most likely trying to run something compiled by a newer Java version with an older Java version. You should check your Java versions. 51.0 is the newer class file format which is supported by JDK7

Saif Asif
  • 5,516
  • 3
  • 31
  • 48
1

You are compiling with 1.7 resulting in 1.7 code. You are trying to use Java 1.6 to execute said code. Doesn't work.

Edit: Either compile with 1.6 (if possible) or use > 1.7 compatible JRE to execute your code.

nils
  • 1,362
  • 1
  • 8
  • 15
  • i have use the command javac -source 1.6 Mouse.java...it is showing error – Srb May 02 '14 at 06:56
  • 1
    You need to use a 1.6 compatible JDK in order to compile for 1.6 (and would have to use the javac executable from the correct directory). But as you do not know whether you can easily compile your code with 1.6: Use a 1.7 compatible JRE instead. – nils May 02 '14 at 06:58
  • can u explain it little bit further – Srb May 02 '14 at 06:59
  • You understand the problem? You compiled for 1.7 but are trying to use 1.6 to execute your code. Therefore you need JRE7. You can find it on Oracle's website. After you have installed it, you can use the java executable from JRE7 to execute your code. – nils May 02 '14 at 07:01
0

You told javac that your source code should be compatible with Java 6 (i.e. it should not use Java 7 specific features like try-with-resources or the diamond operator).

But you didn't tell it to compile class files compatible with Java 6. That is done using the -target 1.6 option.

Quite frankly, I would use the JDK 1.6 to compile your classes if you want the sourcecode and the target class files to be compatible with 1.6. That would guarantee (as the warning message you get tells you) that your code is also not using JDK classes and methods that have been introduced in Java 7.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • should i install jre7 or jdk 1.6??which will be better?? – Srb May 02 '14 at 07:22
  • Start by understanding the difference between JDK and JRE. Then install JDK7 to do Java 7 development, and JDK6 to do Java 6 development. Having both is not a problem. I have 3 JDKs installed on my machine, because some projects are on 6, some on 7, and some on 8. – JB Nizet May 02 '14 at 07:24