14 Replies Latest reply on Dec 21, 2007 4:05 PM by 807603

    Getting java version build number

      Dear Java programmers

      I am trying to extract java version build number, I know you can get java version number by using System.getProperties("java.version"). But if the String version = "1.6.0_10-ea" I just want to retrieve the build number 10.

      This is how I am doing it at the moment

      private static int getJavaVersionBuildNumber(String version) {
      try {
      int index = version.indexOf("_");
      String versionBuild = version.substring(index+1);
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < versionBuild.length(); i++) {
      if (Character.isDigit(versionBuild.charAt(i)))
      else break;
      String versNumber = String.valueOf(sb);
      if (versNumber.equals("")) return -1;
      return Integer.valueOf(versNumber).intValue();
      } catch (Exception e) {
      return -1;

      I would welcome advice if there is a better way of doing this.