How to know JDK version from within Java code

浪尽此生 提交于 2019-12-18 12:12:58

问题


How to know JDK version from within Java code


回答1:


I presume you mean just the Java version, in which case try this:

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



回答2:


Relying on the java.version string for anything else than showing to a human is fragile and will break if running on another Java implementation.

The only reliable way programatically is to use reflection to carefully ask if a given facility is available, and then select the appropriate code accordingly.




回答3:


If you need to know the bit version(32bit or 64 bit) as well, and you are running a hotSpot JVM, you can try this code:

System.getProperty("sun.arch.data.model")

No grantee that it will work for other Java implementaions rather than hotSpot.



来源:https://stackoverflow.com/questions/4638994/how-to-know-jdk-version-from-within-java-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!