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.