Skip to content

Instantly share code, notes, and snippets.

@wfouche
Created July 5, 2025 06:21
Show Gist options
  • Select an option

  • Save wfouche/d77fc8cf9315b944e0dd80b3aac421d7 to your computer and use it in GitHub Desktop.

Select an option

Save wfouche/d77fc8cf9315b944e0dd80b3aac421d7 to your computer and use it in GitHub Desktop.
JVM major version number - Java 8+
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