title: Don't packages have to match the subdirectories the java file is in?
body: <p>I was writing some practice programs for my java certification this morning, and noticed that I had mistyped a package name, so it didn't match the subdirectory the java file was in. I compiled the code expecting an error, but everything compiled file -- not even a warning.</p>
  
  <p>I googled around a bit, and most of the pages I read said that the package name had to match the subdirectory. My experience shows that's not the case. </p>
  
  <p>When I attempted to run the program, it didn't work because the .class file was in the wrong directory. I moved it to the correct directory, and got this error: </p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: com/sample/directory
  /doesnt/even/exist/OtherPackageMemberModifiers (wrong name: com/sample/chap01/O
  therPackageMemberModifiers)
  </code></pre>
  
  <p>So what I think I'm seeing is that Java code will <em>compile</em> if the package and the subdirectory don't match up, but there doesn't seem to be a way to run the code if you do that. Is that correct?</p>