aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding "javac" compiler" Watch "Regarding "javac" compiler" New topic
Author

Regarding "javac" compiler

Loganathan Karunakaran
Ranch Hand

Joined: Nov 04, 2008
Posts: 76
Hi,

Please consider the below classes

Superclass (This is in "food" package):
//Fruit.java
package food;
public abstract class Fruit{ }

Subclass( This is in default package);

//Apple.java
import food.Fruit;
class Apple extends Fruit{ }

Now I just compiled the Apple.java in the default package. But when I went into the "food" folder I see that "Fruit" class is also compiled. It compiled by itself. I didn't compile it.

My question: When we compile a sub-class will it compile the super class also. or How it works? Please explain.

Thanks.


OCPJP 1.6
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
When we compile a sub-class will it compile the super class also. or How it works?

It does it if necessary. To compile Apple.java, Fruit.class is needed - if the class file isn't present the compiler will look for its source code in the same source directory where Apple.java lives. If it doesn't find it, you will get an error.
Loganathan Karunakaran
Ranch Hand

Joined: Nov 04, 2008
Posts: 76
Fine. Thank you.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Lester Burnham wrote:It does it if necessary. To compile Apple.java, Fruit.class is needed - if the class file isn't present the compiler will look for its source code in the same source directory where Apple.java lives. If it doesn't find it, you will get an error.
Even if the class-file of Fruit is found it will recompile Fruit. If the source of Fruit is unavailable then it will use the existing class-file.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Loganathan Karunakaran
Ranch Hand

Joined: Nov 04, 2008
Posts: 76
Thanks Wouter Oet
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Wouter Oet wrote:Even if the class-file of Fruit is found it will recompile Fruit


For more clarity : only if Fruit.java is latest than .class file, else javac uses the class file.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Aha I didn't know that but that makes perfect sense.
Loganathan Karunakaran
Ranch Hand

Joined: Nov 04, 2008
Posts: 76
Thank you Seetharaman.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Loganathan Karunakaran wrote:Thank you Seetharaman.

You are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding "javac" compiler