// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;

public class SetTLS {
    public static void main(String[] args) throws IOException, NoSuchAlgorithmException, KeyManagementException {
        URL url = new URL("https://www.google.com/");
        URLConnection uc = url.openConnection();
        SSLContext ssl = SSLContext.getInstance("TLSv1.2");
        ssl.init(null, null, null);
        ((HttpsURLConnection)uc).setSSLSocketFactory(ssl.getSocketFactory());
        try(BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()))) {
            String line;
            while((line = br.readLine()) != null) {
                System.out.println(line);
            }
        }
        
    }
}
