describe importing classes in javafully qualified


Describe Importing Classes in java?

Fully qualified names such as java.net.URL are not the most convenient thing to have to type. You can use the shorter class names like URL without the java.net part if you first import the class through adding an import statement at the top of the file. For instance,
import java.net.URL;
import java.net.MalformedURLException;

public class URLSplitter {

public static void main(String[] args) {

for (int i = 0; i < args.length; i++) {
try {
URL u = new URL(args[i]);
System.out.println("Protocol: " + u.getProtocol());
System.out.println("Host: " + u.getHost());
System.out.println("Port: " + u.getPort());
System.out.println("File: " + u.getFile());
System.out.println("Ref: " + u.getRef());
}
catch (MalformedURLException e) {
System.err.println(args[i] + " is not a valid URL");
}
}
}
}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: describe importing classes in javafully qualified
Reference No:- TGS0284771

Expected delivery within 24 Hours