Discussion:
How does Javac find source code?
(too old to reply)
Roedy Green
2014-08-05 02:41:00 UTC
Permalink
Back in the days of Java 1.0 I figured out how Javac.exe and Java.exe
find their source code and classes on the sourcepath/classpath.

However one mystery has remained. The question is not a practical one,
just a minor irritant.

Java insists you put each public class in its own source code file
with a name matching the class and the directory structure matching
the package. This is how Java can find the source for a class it
needs. It can generate the source code file name.

However, you are permitted to include a non-public top-level class in
the same source file as a public class. How then does Java find that
non-public class?

Does it just search all the *.java files in that package?
Does it postpone looking for it until it has loaded all the top level
classes it wants, and hope it finds it by serendipity?
--
Roedy Green Canadian Mind Products http://mindprod.com
The art of strongly-typed language design is largely arranging
that errors are automatically detected as soon as possible
in the compose, compile, run cycle.
Jeff Higgins
2014-08-05 21:48:55 UTC
Permalink
Post by Roedy Green
Back in the days of Java 1.0 I figured out how Javac.exe and Java.exe
find their source code and classes on the sourcepath/classpath.
However one mystery has remained. The question is not a practical one,
just a minor irritant.
Java insists you put each public class in its own source code file
with a name matching the class and the directory structure matching
the package. This is how Java can find the source for a class it
needs. It can generate the source code file name.
However, you are permitted to include a non-public top-level class in
the same source file as a public class. How then does Java find that
non-public class?
Does it just search all the *.java files in that package?
Does it postpone looking for it until it has loaded all the top level
classes it wants, and hope it finds it by serendipity?
You might try the Hitchhiker's Guide to start.
<http://openjdk.java.net/groups/compiler/doc/hhgtjavac/index.html>
Loading...