Created
July 5, 2025 06:21
-
-
Save wfouche/d77fc8cf9315b944e0dd80b3aac421d7 to your computer and use it in GitHub Desktop.
JVM major version number - Java 8+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class jmv { | |
| static String getJvmMajorVersion() { | |
| String version = System.getProperty("java.version"); | |
| if (version.startsWith("1.")) { | |
| version = version.substring(2); | |
| } | |
| return version.replaceAll("(\\d+).+", "$1"); | |
| } | |
| public static void main(String[] args) { | |
| System.out.println(getJvmMajorVersion()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment