title: Execute java compiled class command line
body: <p>I have the following question. Given a correctly compiled class whose source code is:</p>
  
  <pre><code>1. package com.sun.sjcp;
  2.
  3. public class Commander {
  4.     public static void main(String[] args) {
  5.         // more code here
  6.     }
  7. }
  </code></pre>
  
  <p>Assume that the class file is located in <code>/foo/com/sun/sjcp/</code>, the current directory is <code>/foo/</code>, and that the classpath contains "." (current directory). Which command line correctly runs Commander?</p>
  
  <pre><code>A. java Commander
  B. java com.sun.sjcp.Commander
  C. java com/sun/sjcp/Commander
  D. java -cp com.sun.sjcp Commander
  E. java -cp com/sun/sjcp Commander
  </code></pre>
  
  <p>Answer: B</p>
  
  <blockquote>
    <p>A. We are in the root dir, so we can't see the file from
    /foo/com/sun/sjcp/ directly </p>
    
    <p>B. is correct</p>
    
    <p><strong>C. I think is correct too ???</strong></p>
    
    <p>D. We are in /foo/com/sun/sjcp/ and there is only class file with
    package <em>package com.sun.sjcp;</em> so the compiler can't find it.
    If the file was without package declaration and was build in this dir
    then it will work if we try to run it in this way.</p>
    
    <p>E. The same as D - does not work</p>
  </blockquote>
  
  <p>The only answer given is B. Where am I making a mistake?</p>