code: public static boolean isSelfIssued(X509Certificate cert) {
          X500Principal subject = cert.getSubjectX500Principal();
          X500Principal issuer = cert.getIssuerX500Principal();
          return subject.equals(issuer);
      }
docs: Utility method to test if a certificate is self-issued. This is
  the case iff the subject and issuer X500Principals are equal.