title: Java current machine name and logged in user?
body: <p>Is it possible to get the name of the currently logged in user (Windows/Unix) and the hostname of the machine?</p>
  
  <p>I assume it's just a property of some static environment class.</p>
  
  <p>I've found this for the user name</p>
  
  <pre><code>com.sun.security.auth.module.NTSystem NTSystem = new
          com.sun.security.auth.module.NTSystem();
  System.out.println(NTSystem.getName());
  </code></pre>
  
  <p>and this for the machine name:</p>
  
  <pre><code>import java.net.InetAddress;
  ...
  String computerName;
  ...
  try {
      computerName = InetAddress.getLocalHost().getHostName();
  }
  
  catch(Exception ex) {
      ...
  }
  </code></pre>
  
  <p>Is the first one just for Windows?</p>
  
  <p>And what will the second one do, if you don't have a hostname set?</p>