What is the difference between URL and URLConnection, Can provide some examples or refer to me??
-
2Well, one is an [URL](http://docs.oracle.com/javase/7/docs/api/java/net/URL.html) and the other is an [URLConnection](http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html) – Brian Roach Jan 12 '14 at 17:48
-
8Basically, the same difference there is between a phone number and a phone call. Read the javadoc. It explains what both classes are. – JB Nizet Jan 12 '14 at 17:48
4 Answers
From Oracle's JAVA API Specification:
Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine.
The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL.
A URL object simply creates an absolute URL, which is used by URLConnection objects created using openConnection() to interact with the URL over a network.

- 1
- 1

- 1,602
- 1
- 13
- 37
According to http://docs.oracle.com/javase/7/docs/api/ URL represents an Uniform Resource Locator, which is merely an address. URLConnection represents a communications link between the application and a URL.

- 2,743
- 2
- 20
- 21
from Oracle web site : "..reading from a URLConnection instead of reading directly from a URL might be more useful. This is because you can use the URLConnection object for other tasks (like writing to the URL) at the same time."

- 231
- 1
- 5
A URL represents the location of a resource, and a URLConnection represents a link for accessing or communicating with the resource at the location.