No.... this really comes down to not knowing, and not using, the API provided to you by the OS for handling version detection.
Almost all of the results in the search are Java applications. Java doesn't provide access to the specified API. The only way you can do it is with System.getProperty("os.name") and System.getProperty("os.version") which both return strings.
The code that turns up in most of the search results is trying to determine the correct executable and arguments to execute a command line (i.e. it picks the right one of "sh -c", "command.com