

Java's URL.equals() Performs DNS Resolution
source link: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URL.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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. More
information on the types of URLs and their formats can be found at:
Types of URL
In general, a URL can be broken into several parts. Consider the following example:
http://www.example.com/docs/resource1.html
The URL above indicates that the protocol to use is http
(HyperText Transfer Protocol) and that the
information resides on a host machine named www.example.com
. The information on that host
machine is named /docs/resource1.html
. The exact
meaning of this name on the host machine is both protocol
dependent and host dependent. The information normally resides in
a file, but it could be generated on the fly. This component of
the URL is called the path
component.
A URL can optionally specify a "port", which is the
port number to which the TCP connection is made on the remote host
machine. If the port is not specified, the default port for
the protocol is used instead. For example, the default port for http
is 80
. An alternative port could be
specified as:
http://www.example.com:1080/docs/resource1.html
The syntax of URL
is defined by
RFC 2396: Uniform
Resource Identifiers (URI): Generic Syntax
, amended by
RFC 2732: Format for
Literal IPv6 Addresses in URLs
. The Literal IPv6 address format
also supports scope_ids. The syntax and usage of scope_ids is describedhere.
A URL may have appended to it a "fragment", also known as a "ref" or a "reference". The fragment is indicated by the sharp sign character "#" followed by more characters. For example,
http://java.sun.com/index.html#chapter1
This fragment is not technically part of the URL. Rather, it
indicates that after the specified resource is retrieved, the
application is specifically interested in that part of the
document that has the tag chapter1
attached to it. The
meaning of a tag is resource specific.
An application can also specify a "relative URL", which contains only enough information to reach the resource relative to another URL. Relative URLs are frequently used within HTML pages. For example, if the contents of the URL:
http://java.sun.com/index.html
contained within it the relative URL:
FAQ.html
it would be a shorthand for:
http://java.sun.com/FAQ.html
The relative URL need not specify all the components of a URL. If the protocol, host name, or port number is missing, the value is inherited from the fully specified URL. The file component must be specified. The optional fragment is not inherited.
The URL class does not itself encode or decode any URL components according to the escaping mechanism defined in RFC2396. It is the responsibility of the caller to encode any fields, which need to be escaped prior to calling URL, and also to decode any escaped fields, that are returned from URL. Furthermore, because URL has no knowledge of URL escaping, it does not recognise equivalence between the encoded or decoded form of the same URL. For example, the two URLs:
http://foo.com/hello world/ and http://foo.com/hello%20world
would be considered not equal to each other.
Note, the
URI
class does perform escaping of its
component fields in certain circumstances. The recommended way
to manage the encoding and decoding of URLs is to use
URI
,
and to convert between these two classes usingand
URI.toURL()
.
The
URLEncoder
and
URLDecoder
classes can also be
used, but only for HTML form encoding, which is not the same
as the encoding scheme defined in RFC2396.
Recommend
-
48
Java 中 hashCode() 和 equals() 的关系是面试中的常考点,如果没有深入思考过两者设计的初衷,这个问题将很难回答。除了应付面试,理解二者的关系更有助于我们写出高质量且准确的代码。 一.基础:hashCode() 和 equals() 简介
-
12
Java基础之String中equals,声明方式,等大总结 转载请注明出...
-
7
Modulator plus amp plus antenna equals illegal fun When I was much younger, I used some technology in a way it probably was not intended to be used. At the time, it all seemed simple enough, and logical, too. What works one way...
-
9
不实现equals方法的情况下比较java list 发表于 2017-04-10...
-
10
Debugging Java Equals and Hashcode Performance in ProductionHashcode and equals are at the crux of many hard to nail down Java performance issues. Here's how to track it in production.
-
4
本文为博主原创,未经允许不得转载: 1. equals 和 hashCode 方法之间的关系 这两个方法都是 Object 的方法,意味着 若一个对象在没有重写 这两个方法时,都会默认采用 Object 类中的方法实现,它们的关系为: 如果两个对...
-
8
A Deep Dive into Java 8 equals() and hashcode()
-
6
【笔记】Java中equals方法的正确使用 2022-10-02 1...
-
8
V2EX › Java Java 里的 equals 方法 lmybill
-
5
Difference between equals method and == operator in java In this post, we can discuss one of the important java interview questions i.e difference between equals() and == operator and sample examples.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK