Академический Документы
Профессиональный Документы
Культура Документы
URL
It uses to analysis the URL on java applications such as the domain name, port
number, path, and etc. in order to deal with specific part of the URL.
URL class 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.
The used functions when you create object are as follow:
1. getFile() The file name of this URL, or an empty string if one does not
exist. The returned file portion will be the same as getPath(), plus the
concatenation of the value of getQuery(), if any. If there is no query portion,
this method and getPath() will return identical results.
2. getProtocol() Returns the protocol name of this URL.
3. getHost() Returns the host name of the URL (domain name).
4. getPort() Returns the port number, or -1 if the port is not set of the URL.
5. getAuthority() Returns the hostname of the URL plus the port number if
exists.
6. getDefaultPort() Returns the default port number of the protocol
associated with this URL. If the URL scheme or the URLStreamHandler for
the URL do not define a default port number, then -1 is returned.
7. getQuery() Returns the query part of this URL, or null if one does not
exist.
8. getPath() Returns the path part of this URL, or an empty string if one does
not exist.
URLConnection class The abstract class URLConnection is the superclass of all
classes that represent a communications link between the application and a URL.
Instances of this class can be used both to read from and to write to the resource
referenced by the URL. Returns an URLConnection instance that represents a
connection to the remote object referred to by the URL.
The used functions when you create object are as follow:
1. getHeaderField(i) Returns the value for the nth header field. It returns null
if there are less than n+1 fields. This method can be used in conjunction with
Code:
Notes:
1. For loop does not have a condition to stop it, which means we need to put
a condition to do so. In our case, we put the value of the header field as a
condition; when it is null to stop the infinite loop.
2. Ports numbers 0-1024 are reserved for privileged services and designated
as well-known ports which defined the ports as an endpoint to a logical
connection and the way a client program specifies a specific server
program on a computer in a network: