Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14845
| From | Jason Kim <iamjsonkim@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How are multiple Java files compiled together? |
| Date | 2012-05-27 16:47 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <19fc754b-0501-46dc-ac81-3589c708e004@googlegroups.com> (permalink) |
| References | <90a3f6ec-dfd4-472b-866d-98eaa92364d5@googlegroups.com> <jpudmj$m0h$1@dont-email.me> |
On Sunday, 27 May 2012 19:34:42 UTC-4, Knute Johnson wrote:
> 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
I didn't know Java compiler could be that smart.
As for the potential problem you mentioned, I don't think I'll have to worry about it any time soon. I won't be programming anything crazy complicated for some time.
Thanks Knute.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How are multiple Java files compiled together? Jason Kim <iamjsonkim@gmail.com> - 2012-05-27 15:48 -0700
Re: How are multiple Java files compiled together? Knute Johnson <nospam@knutejohnson.com> - 2012-05-27 16:34 -0700
Re: How are multiple Java files compiled together? Jason Kim <iamjsonkim@gmail.com> - 2012-05-27 16:47 -0700
Re: How are multiple Java files compiled together? Lew <noone@lewscanon.com> - 2012-05-27 20:18 -0700
Re: How are multiple Java files compiled together? Knute Johnson <nospam@knutejohnson.com> - 2012-05-27 21:08 -0700
Re: How are multiple Java files compiled together? Gene Wirchenko <genew@ocis.net> - 2012-05-28 09:32 -0700
Re: How are multiple Java files compiled together? Lew <noone@lewscanon.com> - 2012-05-28 22:35 -0700
Re: How are multiple Java files compiled together? Gene Wirchenko <genew@ocis.net> - 2012-05-29 09:20 -0700
Re: How are multiple Java files compiled together? Roedy Green <see_website@mindprod.com.invalid> - 2012-05-27 17:35 -0700
Re: How are multiple Java files compiled together? Roedy Green <see_website@mindprod.com.invalid> - 2012-05-27 19:34 -0700
Re: How are multiple Java files compiled together? Roedy Green <see_website@mindprod.com.invalid> - 2012-05-28 04:00 -0700
Re: How are multiple Java files compiled together? Lew <noone@lewscanon.com> - 2012-05-28 22:56 -0700
csiph-web