Error message
Solving process
According to the error information, the reason for the error is that the version of the compiled Java code is different from the current version of java used for running. And the compiled version only supports running versions of 52.0 or above. Thus, it can be seen that the Java version currently used for running is lower than 52.0. First of all, you need to understand what is the compiled version and what is the running version. That is, we need to distinguish JRE from JDK.
When we install the Java environment, one version will correspond to two folders, JRE and JDK. JRE represents the Java runtime environment, that is, the Java runtime environment, while JDK represents the Java se development kit (JDK), that is, the Java compilation environment. We can check whether the versions of the two environments are consistent in CMD (as shown in the following figure):
java – version views the version of JRE (running environment). Javac – version looks at the version of JDK (compilation environment). Note: if you cannot successfully view the version by entering the above command, it indicates that there is a problem with the environment configuration. Please refer to here. Back to the point, if you find inconsistencies after checking the version, reconfigure the environment to ensure that the version is consistent and then recompile and run. It should be noted that I didn’t write the code here, and only got the compiled class file, so I can only solve this problem by changing the running java version. From the error message, we can know that after compilation, this code only supports the JRE environment of java version 52.0 or above. Even if we don’t know which java version 52.0 corresponds to, it must be higher than 1.8.0. In order to avoid problems in the future, I plan to directly update the entire java version, that is, replace JDK and JRE with a new version. Also, considering that 1.8.0 may be needed in the future, I will not delete the 1.8.0 version.
Solution
First download the Java version of 1.9, that is, download the installation package of jdk9.0 (JDK package includes JDK and JRE, 9.0 is 1.9). Here is the network disk link of (windows-x64)
extraction code: 63q0 after downloading and installing, you can start configuring the environment. In order to facilitate management, I put 1.9 under the same path as the previous 1.8. As shown in the following figure:
modify the original Java in the system variable_ Home and JRE_ Home path to point to the newly installed java version of 1.9 (if the way to configure the environment is different from mine, it doesn’t matter. In essence, it’s just that the path to point has changed. I suggest this way to configure it for management convenience. Please refer to the configuration link provided above). As shown below
Check the versions of JDK and JRE again (remember to re open CMD after confirmation)
run the code again and run successfully