Can anyone please explain me the difference between Host Name and Canonical Host Name?
I am currently using InetAddress class to fetch host name using the IP Address. I came across these 2 APIs.
So I am just wondering, which one I should opt for?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a few difference between the two:
getCanonicalHostName()will attempt to resolve the FQDN. Therefore, you would get foo.mycompany.com whereasgetHostName()might just return foo.getCanonicalHostName()will always do a reverse DNS lookup, whereasgetHostName()would return the stored hostname if you supplied one in theInetAddressconstructor.I suspect you will be wanting to use
getCanonicalHostName()if you are intending to map IP addresses to host names.