title: adding class into package
body: <p>I am studying java packages. I successfully created a package pack that contained single .class file Hello.class. Now I want to add another class file into the same package. I named the new java class as Goodbye.java and compiled it into the same directory "pack" via </p>
  
  <pre><code>javac -d ./bin Goodbye.java
  </code></pre>
  
  <p>command. bin directory contains pack directory.
  The I compile  test.java file containing main function  via</p>
  
  <pre><code>javac -cp ./bin test.java
  </code></pre>
  
  <p>command. Compilation works fine. But when I enter </p>
  
  <pre><code>java test 
  </code></pre>
  
  <p>command. I get </p>
  
  <pre><code>Hello, world
  Exception in thread "main" java.lang.NoClassDefFoundError: pack/Goodbye
  at test.main(test.java:9)
  Caused by: java.lang.ClassNotFoundException: pack.Goodbye
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  ... 1 more
  </code></pre>
  
  <p>Can anybody explain what I did wrong in this case? I am working on ubuntu 14.04 and doing everything in the terminal.</p>
  
  <p>Both Hello.java and Goodbye.java files are located in </p>
  
  <pre><code>/home/username/apps/src 
  </code></pre>
  
  <p>directory. Corresponding class files are inside </p>
  
  <pre><code>/home/username/apps/bin/pack
  </code></pre>
  
  <p>directory. pack directory was created by </p>
  
  <pre><code>javac -d ./bin 
  </code></pre>
  
  <p>command.
  Contents of the Hello.java file</p>
  
  <pre><code>package pack;
  public class Hello
  {
      public static void HelloMessage()
      {
          System.out.println("hello, world");
      }
  }
  </code></pre>
  
  <p>It works ok. For its corresponding class file gets loaded
  Contents of Goodbye.java file is </p>
  
  <pre><code>package pack;
  public class Goodbye
  {
      public static void message()
      {
          System.out.println("bye");
      }
  }
  </code></pre>
  
  <p>test.java file which imports the package is located at /home/username/apps directory. It has the following lines of code</p>
  
  <pre><code>import pack.*;
  public class test
  {
      public static void main(String args[])
      {
          Hello.HelloMessage();
          Goodbye.message();
      }
  }
  </code></pre>
  
  <p>Any help is highly appreciated.</p>