This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.

The problem

I am trying to use Notepad ++ as my IDE tool for editing, running, compiling etc.

I have installed the JRE environment and set the path environment variable to… In the /bin directory.

When I run the Hello World program in Notepad ++, I get the following error message:

java.lang.UnsupportedClassVersionError: test_hello_world :
 Unsupported major.minor version 51.0at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) .Copy the code

I think it’s a matter of version: Java versions may be too old or too new.

  1. How do I solve it?
  2. I should installJDKAnd thenpathEnvironment variable is set toJDKRather thanJRE?
  3. inJDKJREpahtWhat is the difference between environment variables?

answer

Answer 1

The version numbers shown below describe the JRE versions that are compatible with the class file.

The corresponding relationship is as follows:

(Source: Wikipedia)

Java SE 17 = 61,
Java SE 16 = 60, 
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
Copy the code

To solve a practical problem, you should try to run Java code using a newer version of the Java JRE, or specify target parameters at Java compile time that tell the compiler to create compatible code.

For example, to generate a Java 1.4-compliant class file, use the following command line:

Javac - target 1.4 HelloWorld. JavaCopy the code

With newer versions of the Java compiler, you may receive warnings that the Bootstrap classpath is not set. For more information about this error message, see article: New Javac Warning for Setting an older source without bootCLASspath.

Answer 2

Java. Lang. UnsupportedClassVersionError because this happens, because you have a high version of the JDK in compiling, and running a lower version of the JDK.

Project -> Properties -> Java Compiler, enable Project Settings, and then select Compiler Compliance Level to 1.7, 1.6, or 1.5 to build and test your application.

conclusion

(Translator’s Note)

The root cause of this problem is that your Java compile time and Java runtime Java versions are inconsistent, that is, the JDK and JRE versions are inconsistent.

To avoid this problem, it is best to ensure that the compilation environment and the runtime environment use exactly the same version.

Translation content sources Stack Overflow:stackoverflow.com/questions/1…