title: How does the Java VM decides the value of the user.dir System property?
body: <p>I'm running a simple Java program with below directory structure:</p>
  
  <pre><code>MyProject (A project in my Eclipse IDE)
   '-- src
        '-- Hello.java
  </code></pre>
  
  <p>In Hello.java I'm printing the value of 'user.dir' System property.</p>
  
  <pre><code>System.out.println(System.getProperty("user.dir"));
  </code></pre>
  
  <p>Compiled file for my class is getting stored in <code>MyProject\bin</code> folder.</p>
  
  <p>When I'm running this class from Eclipse (Right click on source file and click on Run As->Java Application), it prints the path up to 'MyProject' folder, i.e. <code>D:\Projects\Workspace\MyProject</code> in console window.</p>
  
  <p>Then I used the command window to run the same program. This is what I typed on window:</p>
  
  <pre><code>D:\Projects\Workspace\MyProject\bin&gt;java Hello
  </code></pre>
  
  <p>and output on console is: <code>D:\Projects\Workspace\MyProject\bin</code></p>
  
  <p><code>bin</code> has been added to previous value for user.dir.</p>
  
  <p>Further, to check more, I this time executed the Java command from a different folder on command window:</p>
  
  <pre><code>D:\Projects\Workspace\MyProject&gt;java -classpath D:\Projects\Workspace\MyProject\bin Hello
  </code></pre>
  
  <p>This time output on command window is: <code>D:\Projects\Workspace\MyProject</code></p>
  
  <p>This value changes when I changed the folder on command window, and when I'm running the program from Eclipse, the value for user.dir is the project folder. So I would like to understand, what is the basis for deriving the value of 'user.dir'? How does JVM decides, what should be the value for user.dir?</p>