Your code will use the same keystore (loaded from the class loader) as the default keystore and default trust store. This is actually equivalent to setting both -Djavax.net.ssl.keystore* and -Djavax.net.ssl.truststore* with the same value.
This is great if that is what you want to do. (You might want to close the InputStream after you have loaded the keystore.)
This will affect the entire JVM and everything that uses SSLContext.getDefault() , in particular everything that depends on the standard SSLSocketFactory ( URLConnection , etc.).
Since this will be your default trust store, the default centralized trust certificates from the primary CAs will not be in your trust store unless you also explicitly import them into a copy downloaded from the classloader.
Presumably, you will not trust a lot of new CA certificates (or self-signed certificates). It might be more convenient to store the keystore and trust store, since your trust trust can be shared by most of your clients, and usually it will be just a one-time configuration step at the beginning.
source share