Does the Compiler Remember Classes Throughout a Single Compliation?
This question is a bit difficult to explain, but I will give it a go...
Basically, I have a file called sourcefiles.txt which is located at C:\Programming\Test. The contents of sourcefiles.txt are:
Code:
src\com\skywin\store\Item.java
src\com\skywin\store\Storefront.java
src\com\skywin\shop\GiftShop.java
Storefront references Item. GiftShop references both Item and Storefront. None of these java files have been compiled individually yet.
I placed these java files in sourcefiles.txt in order to compile them all at once. So, I entered this into command prompt:
Code:
C:\Programming\Test>javac -d bin @sourcefiles.txt
And all 3 java files compiled successfully. However, I have a problem with this.
It makes sense that Item compiles successfully. However, I thought that in order to compile Storefront.java, I would need to set the classpath to the location where Item.class can be found because Storefront utilizes Item.
Likewise, I thought that in order to compile GiftShop.java, I would need to set the classpath to the location where Item.class and Storefront.class can be found because GiftShop utilizes both Item and Storefront.
I would have to set these classpaths up if I compiled Item individually, and then Storefront individually, and then GiftShop individually. But for some reason, I don't need to do this if all 3 java files are in a single file and compiled all at once.
My only guess at an explanation for this is that the Java compiler "remembers" Item.class while compiling Storefront.java, and likewise the compiler "remembers" Item.class and Storefront.class while compiling GiftShop.java. Perhaps this memory is possible because all 3 files are being compiled during a single compliation.
Can anyone confirm, correct, or add to my theory? Any input would be appreciated!:(happy):
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
The compiler can use source files to compile against.
In your case it finds them as part of the list of files you have asked it to compile, but you could also use the -sourcepath switch. As a side effect it will automatically compile any found source files, though in your case it would do that anyway since you;ve asked it to directly.
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
So if multiple classes are compiled in a list, then the files located in the list are automatically added to the sourcepath?
And also, just a quick question: Is there a way to prevent "Java Code" from showing up above a segment of code if it isn't actually Java code?
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
Quote:
Originally Posted by
awinston
So if multiple classes are compiled in a list, then the files located in the list are automatically added to the sourcepath?
I believe that's the case.
Quote:
Originally Posted by
awinston
And also, just a quick question: Is there a way to prevent "Java Code" from showing up above a segment of code if it isn't actually Java code?
Possibly, but I haven't a clue. Probably an attribute of the code tag?
Personally I don't worry about it...
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
The compiler has a bit of 'make' functionality buit in: if it has to compile a class C that refers to a class D, the compiler needs the compiled D.class file to check whether or not class C can compile fine; therefore class D needs to be on the classpath; additionally when the source of class D (D.java) can be found on the source path (check the -d flag for the compiler), the compiler checks whether or not the source is newer than the compiled version D.class; if so, the compiler also (re)compiles D.java. This behaviour makes 'make' dizzy and lose track of its dependencies and is not very usable for a java compilation task.
kind regards,
Jos
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
Quote:
Originally Posted by
JosAH
The compiler has a bit of 'make' functionality buit in: if it has to compile a class C that refers to a class D, the compiler needs the compiled D.class file to check whether or not class C can compile fine; therefore class D needs to be on the classpath; additionally when the source of class D (D.java) can be found on the source path (check the -d flag for the compiler), the compiler checks whether or not the source is newer than the compiled version D.class; if so, the compiler also (re)compiles D.java. This behaviour makes 'make' dizzy and lose track of its dependencies and is not very usable for a java compilation task.
kind regards,
Jos
Hey Jos! Thanks for the reply. I understand almost all of what you said, but I'm not sure what you mean when you use the term "make". I'm fairly new to programming so maybe it's standard lingo for you guys.:D:
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
Alright, thanks Tolls! :(handshake):
By the way, is there a way to close my thread if I feel that it is resolved?
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
Quote:
Originally Posted by
Tolls
Possibly, but I haven't a clue. Probably an attribute of the code tag?
Personally I don't worry about it...
It's possible that there's an attribute, but this forum's official tutorial doesn't seem to worry about it either...:D: BB Code List - Java Programming Forum
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
I did it for you: you have to edit your original post; go to the 'advanced mode' and set the prefix of the title to '[solved]'.
kind regards,
Jos
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
Alright, thanks Jos! :(y):