Results 1 to 10 of 10
- 07-10-2012, 05:55 PM #1
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
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:
Java Code:src\com\skywin\store\Item.java src\com\skywin\store\Storefront.java src\com\skywin\shop\GiftShop.java
I placed these java files in sourcefiles.txt in order to compile them all at once. So, I entered this into command prompt:
Java Code:C:\Programming\Test>javac -d bin @sourcefiles.txt
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!Last edited by JosAH; 07-11-2012 at 06:07 PM.
- 07-10-2012, 06:41 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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.Please do not ask for code as refusal often offends.
** This space for rent **
- 07-10-2012, 07:14 PM #3
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
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?
- 07-11-2012, 10:54 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
Please do not ask for code as refusal often offends.
** This space for rent **
- 07-11-2012, 12:15 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 07-11-2012, 05:15 PM #6
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
- 07-11-2012, 05:18 PM #7
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
Alright, thanks Tolls!
By the way, is there a way to close my thread if I feel that it is resolved?
- 07-11-2012, 05:27 PM #8
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Re: Does the Compiler Remember Classes Throughout a Single Compliation?
It's possible that there's an attribute, but this forum's official tutorial doesn't seem to worry about it either...
BB Code List - Java Programming Forum
- 07-11-2012, 06:08 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 07-11-2012, 06:13 PM #10
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Similar Threads
-
Remember the text in JTextField
By seredi in forum New To JavaReplies: 11Last Post: 09-21-2011, 07:55 PM -
need help Coding RADIO BUTTON for REMEMBER ME
By timosoft in forum New To JavaReplies: 5Last Post: 02-04-2011, 11:15 PM -
Can't Remember How to Do This
By mandalay92 in forum New To JavaReplies: 3Last Post: 08-30-2008, 03:24 AM -
More efficient in memory? Multiple Jars or Single Jars with lot's of Classes
By dark_cybernetics in forum New To JavaReplies: 0Last Post: 08-19-2008, 05:44 PM -
JFileChooser remember the location
By Mr tuition in forum AWT / SwingReplies: 3Last Post: 12-08-2007, 06:17 PM
Bookmarks