How to know JDK version from within Java code
Type "java -version" into the Command Prompt, then press Enter on your keyboard. After a moment, your screen should display the information your computer has about Java, including what version you have installed.
I presume you mean just the Java version, in which case try this:
String version = System.getProperty("java.version");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With