First download certificate in java file
echo -n | openssl s_client -servername <hostname> -connect <hostname>:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/key.cert
Import it using keytool command
keytool -import -alias <alias> -file key.cert -keystore <keystore_location>
Java Trust store location : <JRE_HOME>/lib/security/cacerts