This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a problem to understand the meaning of the connect() method in the URLConnection class.
In the following code, if I use the connect() method, I get the same result if I don't use it.
Why (or when) do I need to use it?
Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.
In other words, if you don't call connect() but you call some other method which needs to be connected, that other method will call connect() itself if it isn't already connected. Does that clarify things for you?