New API limitations

There are some intentional shortcomings of the new API. While this might sound counter-intuitive, the new API was not intended to completely replace the current HttpURLConnection API. Instead, the new API is intended to eventually replace the current one.

The following code snippet provides an example of how to implement the HttpURLConnect class to open and read a URL in a Java application:

    /*    import statements    */

    public class HttpUrlConnectionExample
    {  
      public static void main(String[] args) 
      {
        new HttpUrlConnectionExample();
      }
  
      public HttpUrlConnectionExample()
      {        URL theUrl = null;        BufferedReader theReader = null;        StringBuilder theStringBuilder;         // put the URL into a String String theUrl = "https://www.packtpub.com/"; ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.