code: static int javaMajorVersion(String javaVersion) {
      String[] version = javaVersion.split("[+.\\-]+");
      int major = Integer.parseInt(version[0]);
      // if major > 1, we're using the JEP-223 version string, e.g., 9-ea, 9+120
      // otherwise the second number is the major version
      if (major > 1) {
        return major;
      } else {
        return Integer.parseInt(version[1]);
      }
    }
docs: Get the major version of the java version string supplied. This method
  accepts any JEP-223-compliant strings (9-ea, 9+100), as well as legacy
  version strings such as 1.7.0_79