Click to See Complete Forum and Search --> : javac *.java??


nmarun
December 19th, 2002, 04:29 PM
Dear Gurus,

I want to know, how the command

javac *.java

works?

Let me make the question more descriptive. Here's the situation:

Say I have 4 classes in a package - A, B, C and D.

Class B inherits class A and class C imports class D.

Given the above conditions, at the command prompt, if I compile using the above command, how exactly will compiling begin?

Since B requires A, A should be compiled before B and again C requires D, so D needs to be compiled before C.

More explanation plz..

tia
Arun

dlorde
December 19th, 2002, 07:29 PM
Javac will compile the source files in the order they are presented. If it encounters a type it doesn't recognise, it will look for a source file or class file which defines the type. The compiler searches first in the bootstrap and extension classes, then in the user class path. If you use the -sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path both for class files and source files.

A successful type search may produce a class file, a source file, or both. Here is how javac handles each situation:

a. Search produces a class file but no source file: javac uses the class file.

b. Search produces a source file but no class file: javac compiles the source file and uses the resulting class file.

c. Search produces both a source file and a class file: javac determines whether the class file is out of date. If the class file is out of date, javac recompiles the source file and uses the updated class file. Otherwise, javac just uses the class file.
javac considers a class file out of date only if it is older than the source file.

So source files are compiled as needed to satisfy the type references encountered. This implies a potentially recursive structure of compilation.

nmarun
December 19th, 2002, 08:10 PM
Hi Dave,

That was too technical.. my first reading made least sense to me but a couple more readings did make sense to me.

I had no idea that a simple command like this one would be sooo complicated.

Abt java,
"The more I learn , the more there's to learn.
The more I understand, the more it amazes me."

Thnx Dave
Arun

dlorde
December 20th, 2002, 09:39 AM
Sorry, but that was the least technical description I could find! Most of the details on how compilers parse 'translation units' (source files) involve discussions on 'recursive descent parsing trees', and involve highly technical symbolic logic expressions...

Basically, the compiler compiles the files in the order given, and if it finds a type it doesn't recognise, it uses a simple set of rules to search for it in other source or class files.

If it finds it in a source file, it has to compile the source file before it can be used. It also makes sure the class files it finds are not out of date.

Doesn't sound that technical to me... still, YMMV :D

nmarun
December 20th, 2002, 01:25 PM
Hi Dave,

Thnx for the update again..

Arunq