title: Could not find or load main class in a simple java project
body: <p>I have created a simple java project &quot;DesignPatterns&quot;.
  I created a file FacadePattern.java with the path being <code>~/DesignPatterns/Structural/FacadePattern/FacadePattern.java</code></p>
  <p>My <code>FacadePattern.java</code> class,</p>
  <pre><code>public class FacadePattern {
      public static void main(String args[]) {
          // Some code
      }
  }
  </code></pre>
  <p>But my editor (VSCode) gives me an error at the start of the file:
  <code>The declared package &quot;&quot; does not match the expected package &quot;Structural.DecoratorPattern&quot;</code></p>
  <p>So upon clicking on quick fix, it added <code>package Structural.FacadePattern;</code> in the first line.</p>
  <p>So the final code became</p>
  <pre><code>package Structural.FacadePattern;
  
  public class FacadePattern {
      public static void main(String args[]) {
          // Some code
      }
  }
  </code></pre>
  <p>But when I compile the above file using the command</p>
  <pre><code>javac FacadePattern.java &amp;&amp; java FacadePattern
  </code></pre>
  <p>It is giving me the following error:</p>
  <pre><code>Error: Could not find or load main class FacadePattern
  Caused by: java.lang.NoClassDefFoundError: Structural/FacadePattern/FacadePattern (wrong name: FacadePattern)
  </code></pre>
  <p>After searching a lot in the internet, I ran the following command:</p>
  <pre><code>javac -sourcefile ~/DesignPatterns FacadePattern.java &amp;&amp; java FacadePattern
  </code></pre>
  <p>But no use, I am getting the same error.</p>
  <p>Can anyone explain why my editor gave an error but code ran successfully before? and why wont it compile after adding &quot;package Structural.FacadePattern;&quot; line? and what is -sourcefile parameter in javac command? and how to run the code with successfully without errors in editor as well as the terminal?</p>