Extract a Public Cert from a Java Keystore/Truststore

It can be useful to pull the public certificate out of a Java keystore (maybe called a truststore in this case, as it may just store public certs).
We can pull the cert out by running the following, which will return the X509 PEM-encoded certificate:
keytool -list -alias selfsigned -rfc -keystore keystore.jks -storepass password | \
sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p'