Last Updated: June 6, 2026
The previous lesson built a URL and parsed it apart. That gives you an address, nothing more. To actually talk to the server at that address, you need a connection. URLConnection is the abstract class that represents a live link between your Java program and a resource on the network. For HTTP and HTTPS URLs, the concrete subclass you get back is HttpURLConnection, and that is what powers most of the HTTP traffic in older Java code.
This lesson covers the full request lifecycle: opening the connection, picking the HTTP method, setting headers, applying timeouts, sending a request body, reading the response, and cleaning up. Almost every example wraps a real e-commerce task: charging a card, fetching a shipping rate, looking up an exchange rate, or posting an order webhook. By the end, you will see why URLConnection works but feels rough, and why the modern HttpClient API has largely replaced it for new code.