Install certificate in keystore using java

I want to install .pem cert in keystore using java code which we do using keytool command in command line. I have imported my cert as string from consul.