If by 'connecting https URL' you mean specifically the java.net.URL
class and something like new java.net.URL("https://something") .openConnection()
which returns an implementation (subclass) of javax.net.HttpsURLConnection
here are two examples as I referenced:
static void SO49993912ExampleClientPKCS12 (String[] args) throws Exception {
FileInputStream fis = new FileInputStream (args[0]);
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load (fis, args[1].toCharArray()); fis.close();
KeyManagerFactory kf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kf.init (ks, args[1].toCharArray());
SSLContext ctx = SSLContext.getInstance ("TLS");
ctx.init (kf.getKeyManagers(), null /*default TM(s)*/, null);
// method 1
HttpsURLConnection conn1 = (HttpsURLConnection) new URL (args[2]).openConnection();
conn1.setSSLSocketFactory(ctx.getSocketFactory());
conn1.connect(); System.out.println (conn1.getResponseCode()); conn1.disconnect();
// method 2
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
HttpsURLConnection conn2 = (HttpsURLConnection) new URL (args[2]).openConnection();
conn1.connect(); System.out.println (conn2.getResponseCode()); conn2.disconnect();
}
However there are lots and lots of other ways of connecting to https (and other) URLs in Java; if you actually meant something else you have to be more specific.