For getting data from remote url which connection type will work fast URLConnection or Socket.
Although it depends on the type of data, server etc.
I agree with r0ast3d.
According to me if server allows both the things, then I would prefer to use URLConnection.
Both sends data using streams, but wait mode in Socket is bit high than in URLConnection.
Please correct me If I am wrong.
From tutorial http://docs.oracle.com/javase/tutorial/networking/urls/connecting.html URLConnection IS NOT abstract and can be instanciated
Would love to see some benchmarks on which one is faster though.
Presumably you mean the java "URLConnection" library versus or raw Sockets.
As URL connection uses sockets internally then logically sockets should a little bit faster as http makes all the socket calls plus some overhead in handling the full protocol.
In practice I would expect very little difference. If you code up your own sockets interface you will need to do most the extra processing carried out by the URL connection in order to make the sockets connection workable and reliable.
Also the java "URLConnection" library was probably written by programmers who are better than you or I. Certainly 10 years on most of the bugs have been found. So why not take advantage of that skill and experience and use the simpler URLConnection.
It does not matter which one is faster both of these have different purposes. A socket is an endpoint for communication between two machines and need to access different protocol. 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. In short if you need to communicate with the other machine or device implement socket and if you want to read data from server use URLconnection.
Happy Coding :D
Both have different purposes, depending upon your need
A socket can implement almost a duplex kind of functionality, whereas a url connection can connect to a given URI and read its content.