How to use proxies in Java Coding

Java using it’s own coding language to implement the proxy. Here is an example of code that would use a proxy.


import java.net.*;
import java.util.Scanner;
 class ProxyTest {
  public static void main(String[] args) throws Exception {
    InetSocketAddress proxyAddress = new InetSocketAddress("1.1.1.1", 8800); // Set proxy IP/port.
    Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
    URL url = new URL("https://checkip.instantproxies.com/");
    URLConnection urlConnection = url.openConnection(proxy);
    Scanner scanner = new Scanner(urlConnection.getInputStream());
    System.out.println(scanner.next());
    scanner.close();
  }
}