code: public static int getJavaMajorVersion() {
  
          final String[] versionElements = System.getProperty(JAVA_VERSION_PROPERTY).split("\\.");
          final int[] versionNumbers = new int[versionElements.length];
  
          for (int i = 0; i < versionElements.length; i++) {
              try {
                  versionNumbers[i] = Integer.parseInt(versionElements[i]);
              } catch (NumberFormatException e) {
                  versionNumbers[i] = 0;
              }
          }
  
          /*
          Java versions 1 - 8 (i.e. jdk 1.1 through 1.8) yields the structure 1.8
          Java versions 9 - yields the structure 10
  
          JDK 10
          ======
          [java.specification.version]: 10
  
          JDK 8
          =====
          [java.specification.version]: 1.8
  
          JDK 7
          =====
          [java.specification.version]: 1.7
          */
          return versionNumbers[0] == 1 ? versionNumbers[1] : versionNumbers[0];
      }
docs: Retrieves the major java runtime version as an integer.
  
  @return the major java runtime version as an integer.