code: public static String getCompiledJavaMajorVersionFromJavaClassFileAsString(
          InputStream classByteStream) throws Exception {
          int majorVersion = getCompiledJavaVersionFromJavaClassFile(classByteStream, true);
          switch (majorVersion) {
              case 50:
                  return "Java 6";
              case 51:
                  return "Java 7";
              case 52:
                  return "Java 8";
              default:
                  return "Could not find version string for major version: " + majorVersion;
          }
      }
docs: getCompiledJavaMajorVersionFromJavaClassFileAsString, Given an input stream to a Java class
  file, this will return the major version of Java that was used to compile the file (as a
  string). In a Maven POM file, this is known as the "target" version of Java that was used to
  compile the file.
  
  Getting an input stream for a class file inside a jar file:
  
  InputStream input = getClass().getResourceAsStream("/classpath/to/my/file.class");