The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
Historically, an Internet domain name contained ASCII symbols only. As the Internet gained popularity and was adopted across the world, it became necessary to support internationalization of domain names, specifically to support domain names that include Unicode characters.
The Internationalizing Domain Names in Applications (IDNA) mechanism was adopted as the standard to convert Unicode characters to standard ASCII domain names and thus preserve the stability of the domain name system. This system performs a lookup service to translate user-friendly names into network addresses.
Examples of internationalized domain names:
If you follow these links you will see that the Unicode domain name represented in the address bar is substituted with the ASCII string.
To implement similar functionality in your application, the java.net.IDN class provides methods to convert domain names between ASCII and non ASCII formats.
Method | Purpose |
---|---|
toASCII(String) toASCII(String, flag) |
Used before sending an IDN to the domain name resolving system or writing an IDN to a file where ASCII characters are expected, such as a DNS master file. If the input string doesn't conform to RFC 3490, these methods throw an IllegalArgumentException. |
toUnicode(String) toUnicode(String, flag) |
Used when displaying names to users, for example names obtained from a DNS zone. This method translates a string from ASCII Compatible Encoding (ACE) to Unicode code points. This method never fails; in case of an error the input string remains the same and is returned unmodified. |
The optional flag parameter specifies the behavior of the conversion process. The ALLOW_UNASSIGNED flag allows including code points that are unassigned in Unicode 3.2. The USE_STD3_ASCII_RULES flag ensures that the STD-3 ASCII rules are observed. You can use these flags separately or logically OR'ed together. If neither flag is desired, use the single-parameter version of the method.