14 Replies Latest reply: Dec 21, 2007 6:43 AM by 807603 RSS

    Getting java version build number

    807603
      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)))
      sb.append(versionBuild.charAt(i));
      else break;
      }
      String versNumber = String.valueOf(sb);
      if (versNumber.equals("")) return -1;
      return Integer.valueOf(versNumber).intValue();
      } catch (Exception e) {
      e.printStackTrace();
      return -1;
      }
      }

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


      Regards