code: public static boolean isSelfSigned(X509Certificate cert) {
          try {
              cert.verify(cert.getPublicKey());
              return true;
          } catch (SignatureException e) {
              return false;
          } catch (InvalidKeyException e) {
              return false;
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
docs: Checks whether given X.509 certificate is self-signed.
  
  @param cert
  @return true if the certificate is self-signed