VersionParser { static VersionNumber identifyJavaVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("Java/((\\d+)((\\.\\d+)+)?((\\-|_)[\\w\\d\\-]+)?)")); patterns.add(Pattern.compile("Java((\\d+)((\\.\\d+)+)?((\\-|_)[\\w\\d\\-]+)?)")); for (final Pattern pattern : patterns) { final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX)); break; } } return version; } private  VersionParser(); static VersionNumber parseLastVersionNumber(@Nonnull final String text); static VersionNumber parseOperatingSystemVersion(@Nonnull final OperatingSystemFamily family, @Nonnull final String userAgent); static VersionNumber parseVersion(@Nonnull final String version);  }
@Test public void identifyJavaVersion() { assertThat(VersionParser.identifyJavaVersion("Java1.2").toVersionString()).isEqualTo("1.2"); assertThat(VersionParser.identifyJavaVersion("Java1.4.2_07").toVersionString()).isEqualTo("1.4.2_07"); assertThat(VersionParser.identifyJavaVersion("BlogBridge Service Java/1.4.2_07").toVersionString()).isEqualTo("1.4.2_07"); assertThat(VersionParser.identifyJavaVersion("Java/1.6.0-beta").toVersionString()).isEqualTo("1.6.0-beta"); assertThat(VersionParser.identifyJavaVersion("Java/1.7.0_04-ea").toVersionString()).isEqualTo("1.7.0_04-ea"); }