Results 1 to 10 of 10
  1. #1
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default 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
    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:

    Java 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!
    Last edited by JosAH; 07-11-2012 at 06:07 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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 **

  3. #3
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default 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?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Does the Compiler Remember Classes Throughout a Single Compliation?

    Quote Originally Posted by awinston View Post
    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 View Post
    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...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Does the Compiler Remember Classes Throughout a Single Compliation?

    Quote Originally Posted by JosAH View Post
    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.

  7. #7
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default 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?

  8. #8
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Does the Compiler Remember Classes Throughout a Single Compliation?

    Quote Originally Posted by Tolls View Post
    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... BB Code List - Java Programming Forum

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Does the Compiler Remember Classes Throughout a Single Compliation?

    Alright, thanks Jos!

Similar Threads

  1. Remember the text in JTextField
    By seredi in forum New To Java
    Replies: 11
    Last Post: 09-21-2011, 07:55 PM
  2. need help Coding RADIO BUTTON for REMEMBER ME
    By timosoft in forum New To Java
    Replies: 5
    Last Post: 02-04-2011, 11:15 PM
  3. Can't Remember How to Do This
    By mandalay92 in forum New To Java
    Replies: 3
    Last Post: 08-30-2008, 03:24 AM
  4. Replies: 0
    Last Post: 08-19-2008, 05:44 PM
  5. JFileChooser remember the location
    By Mr tuition in forum AWT / Swing
    Replies: 3
    Last Post: 12-08-2007, 06:17 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •