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.