I\'ve been getting hostname of the machine as follows:
InetAddress.getLocalHost().getHostName();
However, when I put latest JDK (jdk1.7.0_04),
If you're not against using an external dependency from maven central, I wrote gethostname4j to solve this problem for myself. It just uses JNA to call libc's gethostname function (or gets the ComputerName on Windows) and returns it to you as a string.
https://github.com/mattsheppard/gethostname4j
@edward-thomson's answer above makes me thing I might have a bit more work to do to make it work well on MacOS though :)