Java allows multiple top-level class declaration per file, at the condition that at most one of those class is public.
However, the Oracle Java compiler seems to have trouble resolving those kinds of dependencies. Consider:
// One.java
package jtest;
import jtest.Three;
public class One {}
// Two.java
package jtest;
public class Two {}
class Three {}
This first attempt to compile ends in an error:
javac -cp . jtest\One.java
jtest\One.java:3: error: cannot find symbol
import jtest.Three;
^
symbol: class Three
location: package jtest
1 error
This however works as expected
javac -cp . jtest\Two.java
javac -cp . jtest\One.java
Now, this is "known" behaviour (it is reported in this answer for instance). However, most build systems don't seem to have problems with the scenario (I tried Eclipse and Apache Buildr). How do they resolve the problem?
Also consider that both Eclipse and Apache Buildr can compile this without batting an eyelash:
// One.java
package main;
import main.Four;
public class One {}
class Three {}
// Two.java
package main;
import main.Three;
public class Two {}
class Four {}