Java Networking - Sockets and RMI Question:

Download Job Interview Questions and Answers PDF

How do I make a connection to URL?

Java Networking - Sockets and RMI Interview Question
Java Networking - Sockets and RMI Interview Question

Answer:

You obtain a URL instance and then invoke openConnection on it. URLConnection is an abstract class, which means you can’t directly create instances of it using a constructor. We have to invoke openConnection method on a URL instance, to get the right kind of connection for your URL. Eg. URL url;

URLConnection connection;
try {
url = new URL(”…”);
connection = url.openConnection();
} catch (MalFormedURLException e) { }

Download Java Networking - Sockets and RMI Interview Questions And Answers PDF

Previous QuestionNext Question
What is the difference between URL instance and URLConnection instance?What Is a Socket in Java Networking and RMI?