title: running java from command line
body: <p>I have been mostly using eclipse so far. Now I'm trying to run java from terminal but I have a problem with packages.</p>
  
  <p>This is my <code>Main.java</code> file:</p>
  
  <pre><code>package main;
  
  class Main {
      public static void main(String[] args) {
          System.out.println("it's working");
      }
  }
  </code></pre>
  
  <p>I compile this using <code>javac Main.java</code> and then run with <code>java Main</code> which gives me:</p>
  
  <pre><code>java Main
  Exception in thread "main" java.lang.NoClassDefFoundError: Main
  Caused by: java.lang.ClassNotFoundException: Main
          at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  Could not find the main class: Main. Program will exit.
  </code></pre>
  
  <p><strong>When I remove <code>package Main</code> everything works fine. What am I missing?</strong></p>
  
  <p><code>java -version</code> gives:</p>
  
  <pre><code>java version "1.6.0_24"
  OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1)
  OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
  </code></pre>