Java:如何检查 jdk 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12616301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:34:11  来源:igfitidea点击:

Java: How to check jdk version?

java

提问by hemu

Possible Duplicate:
How to know JDK version from within Java code

可能的重复:
如何从 Java 代码中知道 JDK 版本

In my java code I want to check jdkversion. If it is 1.5 or above than & than only I want to go ahead with further execution. How to get the jdkversion ?

在我的 java 代码中,我想检查jdk版本。如果它是 1.5 或更高,而不是 & 比我想继续进一步执行。如何获取jdk版本?

回答by Ingo Kegel

Use this condition

使用这个条件

Integer.parseInt(System.getProperty("java.version").split("\.")[1]) >= 5

to check the Java version.

检查 Java 版本。

回答by maba

String version = System.getProperty("java.specification.version");

That will give you the string 1.5for example. Easy to parse.

例如,这将为您提供字符串1.5。易于解析。

回答by David Grant

String version = System.getProperty("java.version");