title: Java URLConnection - When do I need to use the connect() method?
body: <p>I have a problem to understand the meaning of the <code>connect()</code> method in the <code>URLConnection</code> class. In the following code, if I use the <code>connect()</code> method, I get the same result if I don't use it.</p>
  
  <p>Why (or when) do I need to use it?</p>
  
  <pre><code>URL u = new URL("http://example.com");
  HttpURLConnection conn = (HttpURLConnection) u.openConnection();
  
  conn.connect();//with or without it I have the same result
  
  InputStream in = conn.getInputStream();
  int b;
  while ((b = in.read()) != -1) {
   System.out.write(b);
  }
  </code></pre>