code: public static int getCompiledJavaVersionFromJavaClassFile(
          InputStream classByteStream, boolean majorVersionRequested)
          throws Exception {
          DataInputStream dataInputStream = new DataInputStream(classByteStream);
          // Skip the "magic number".
          dataInputStream.readInt();
          int minorVersion = dataInputStream.readUnsignedShort();
          int majorVersion = dataInputStream.readUnsignedShort();
          return (majorVersionRequested) ? majorVersion : minorVersion;
      }
docs: getCompiledJavaVersionFromJavaClassFile, Given an input stream to a Java class file, this
  will return the major or minor version of Java that was used to compile the file. 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");