wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Need clarification on classpath from SCJP1.6 - Please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need clarification on classpath from SCJP1.6 - Please help" Watch "Need clarification on classpath from SCJP1.6 - Please help" New topic
Author

Need clarification on classpath from SCJP1.6 - Please help

Kathirvel Subakaran
Greenhorn

Joined: Jun 04, 2010
Posts: 4
Hi all, I need your help on this. Its driving me crazy. Please explain the q&a below a bit more.. My doubt is, javac will look in the current directory for B.java which is in a package, so we need to mention xcom/B.java. How about A.class it's also in that package, should we not mention it as ./xcom

Given the default classpath:
/foo

And this directory structure:
foo
|
test
|
xcom
|--A.class
|--B.java
And these two files:
package xcom;
public class A { }
package xcom;
public class B extends A { }


Which allows B.java to compile? (Choose all that apply.)
A. Set the current directory to xcom then invoke
javac B.java

B. Set the current directory to xcom then invoke
javac -classpath . B.java

C. Set the current directory to test then invoke
javac -classpath . xcom/B.java

D. Set the current directory to test then invoke
javac -classpath xcom B.java

E. Set the current directory to test then invoke
javac -classpath xcom:. B.java

Answer:

C is correct. In order for B.java to compile, the compiler first needs to be able to find
B.java. Once it's found B.java it needs to find A.class. Because A.class is in the
xcom package the compiler won't find A.class if it's invoked from the xcom directory.
Remember that the -classpath isn't looking for B.java, it's looking for whatever classes
B.java needs (in this case A.class).

A, B, and D are incorrect based on the above. E is incorrect because the compiler can't
find B.java
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Welcome to JavaRanch.

This exact same question has been asked before on the forums here. If you search for "xcom", you will find some of the older topics discussing this question.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Kathirvel Subakaran
Greenhorn

Joined: Jun 04, 2010
Posts: 4
Thanks Jesper. But still I couldn't find the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need clarification on classpath from SCJP1.6 - Please help