Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: How are multiple Java files compiled together? Date: Sun, 27 May 2012 16:34:42 -0700 Organization: A noiseless patient Spider Lines: 64 Message-ID: References: <90a3f6ec-dfd4-472b-866d-98eaa92364d5@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 27 May 2012 23:34:44 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="22545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193YuSeN3E5HgCGxyRA7tOX" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: <90a3f6ec-dfd4-472b-866d-98eaa92364d5@googlegroups.com> Cancel-Lock: sha1:WAfxhmhBgra/wwvR4AHR0dQj1Lo= Xref: csiph.com comp.lang.java.programmer:14844 On 5/27/2012 3:48 PM, Jason Kim wrote: > I am new to Java. > > Here are two files. > > VolcanoApplication.java > class VolcanoApplication { > public static void main(String[] arguments) { > VolcanoRobot dante = new VolcanoRobot(); > dante.status = "exploring"; > dante.speed = 2; > dante.temperature = 510; > > dante.showAttributes(); > System.out.println("Increasing speed to 3."); > dante.speed = 3; > dante.showAttributes(); > System.out.println("Changing temperature to 670"); > dante.temperature = 670; > dante.showAttributes(); > System.out.println("Checking the temperature."); > dante.checkTemperatur(); > dante.showAttributes(); > } > } > > VolcanoRobot.java > class VolcanoRobot { > String status; > int speed; > float temperature; > > void checkTemperatur() { > if (temperature> 50) { > status = "returning home"; > speed = 5; > } > } > > void showAttributes() { > System.out.println("Status: " + status); > System.out.println("Speed: " + speed); > System.out.println("Temperature: " + temperature); > } > } > > I compiled the program by doing > $ javac VolcanoApplication.java > > But how does Java know that VolcanoRobot.java should also be in the compilation? If it didn't know, think about what a pain that would be every time you had to compile a program with a lot of files. You reference VolcanoRobot in VolcanoApplication, the compiler looks for that that class in the classpath and compiles it if necessary. That feature can be the source of a very tricky problem and that is if there is a VolcanoRobot.class file in the classpath the compiler won't compile VolcanoRobot.java even if it has changed since the VolcanoRobot.class file was created. -- Knute Johnson