title: Why does javac not find my class file in the same package?
body: <p>I am trying to understand Java packages.</p>
  
  <p>I have two classes, A.java and B.java, in the same package.
  Class A references class B.</p>
  
  <p>Both have package statements <code>package world.example;</code> and are saved in a directory<code>.../world/example/</code>.</p>
  
  <p>B compiles ok, but when attempting to compile A, javac fails to find the classfile for B.</p>
  
  <p>I have tried running javac from the parent of <code>/world</code> as well as from <code>/example</code>.   I have searched many answers both here and elsewhere, to no avail.   Most questions on similar topics seem to have much extraneous code and information, so I have tried to distil my issue down to its bare bones but still cannot see what I am missing.</p>
  
  <p>Addendum:  if I remove the package statements, both classes compile ok provided I specify the classpath when compiling A, thus: <code>javac -classpath . A.java</code>.</p>
  
  <p>Code follows:</p>
  
  <pre><code>package world.example;
  
  public class A {    
    public static void main(String[] args) {
      String msg = B.getMessage();
      System.out.println(msg);
    }     
  }
  </code></pre>
  
  <p>...and...</p>
  
  <pre><code>package world.example;
  
  public class B {    
      protected static String getMessage() {
          return "Hello world!";
      }       
  }
  </code></pre>
  
  <p>...and the output from javac...</p>
  
  <pre><code>17-04-17◆23:03 example »javac B.java 
  17-04-17◆23:04 example »javac A.java 
  A.java:5: error: cannot find symbol
          String msg = B.getMessage();
                       ^
    symbol:   variable B
    location: class A
  1 error
  17-04-17◆23:04 example »javac -classpath . A.java
  A.java:5: error: cannot find symbol
          String msg = B.getMessage();
                       ^
    symbol:   variable B
    location: class A
  1 error
  </code></pre>