Skip to main content

Posts

Showing posts with the label URL Connection

Java URL Connection Interview Questions

Explain the difference between a URL instance and a URL connection instance. URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location Explain how to make a connection to a URL. Connection to the remote object represented by the URL is only initiated when the connect() method of the URLConnection is called. Doing this initializes a communication link between your Java program and the URL over the network. The following code show how a connection to a URL is made. try { URL xyz = new URL( http://www.xyz.com/ ); URLConnection xyzConnection = xyz.openConnection(); xyzConnection.connect(); } catch (MalformedURLException e) { // new URL() failed . . . } catch (IOException e) { // openConnection() failed . . . } Explain how to read from a remote file when we have its URL. With the help of the following code you could dir...