Java Reference
In-Depth Information
try
{
URL u = new URL("http;//www.httprecipes.com/");
} catch (MalformedURLException e)
{
e.printStackTrace();
}
The MalformedURLException would be thrown because the “http” protocol
specified ends with a semicolon instead of a colon.
What is a URL
In the last section I showed how to construct a URL object. You also saw that a
MalformedURLException would be thrown if an invalid URL is specified. To under-
stand what an invalid URL is, you should first understand the format of a good URL. URLs
follow the following format:
URL Scheme://Host/Path?Query
As seen above, the URL is made up of the following three components:
• Scheme
• Host
• Path
• Query
In the next few sections, each of these components will be discussed. We will start with
the URL scheme.
URL Scheme
The scheme is the protocol that will be used to transfer data. For the purposes of this
topic, we will be dealing with the “http” and “https” schemes. Many of the more common
schemes are listed in Table 3.1.
Search WWH ::




Custom Search