All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.
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 the class A.class).
A, B and D are incorrect based on the above. E is incorrect because the compiler can't find B.java.
Abhi vijay wrote:javac -classpath . xcom/B.java
what does this line imply??
SCJP 6
Abhi vijay wrote:javac -classpath . xcom/B.java
what does this line imply??
All code in my posts, unless a source is explicitly mentioned, is my own.
Punit Singh wrote:No Ruben, I think if this one were given,
then it will be valid.
All code in my posts, unless a source is explicitly mentioned, is my own.
Sachin Adat,
One thing to remember compiler is always looking for xcom.A and not A
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Ruben Soto wrote:
Only answer 3. is correct. Why? Because you must include test in the classpath. That's the only answer that includes test in the classpath. Do you understand why test must be in the classpath?
James Tharakan wrote:
Sachin Adat,
One thing to remember compiler is always looking for xcom.A and not A
What does this mean???
SCJP 6
James Tharakan wrote:
Sachin Adat,
One thing to remember compiler is always looking for xcom.A and not A
What does this mean???
F:\workspace\scjp\src\xcom>javac A.java
F:\workspace\scjp\src\xcom>javac B.java
B.java:3: cannot find symbol
symbol: class A
public class B extends A{
^
1 error
SCJP 6
Sachin Adat wrote:
Ruben Soto wrote:
Only answer 3. is correct. Why? Because you must include test in the classpath. That's the only answer that includes test in the classpath. Do you understand why test must be in the classpath?
For finding xcom.A you need to have test in classpath or atleast you have to be in test directory which Punit pointed out, but it is not in the options.
So I think you were right.
Correct me if I am wrong.....
All code in my posts, unless a source is explicitly mentioned, is my own.
Abhi vijay wrote:if i change option 4 to
javac - classpath xcom/B.java (current directory is test)
then B.java would compile right?
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abhi vijay wrote:if i change option 4 to
javac - classpath xcom/B.java (current directory is test)
then B.java would compile right?
Abhi vijay wrote:
One more doubt,
javac -classpath xcom:. B.java ( current directory is test) what does this line imply?
SCJP 6
Prav sharma wrote:The final and useful tip to solve this question from K & B is to see in this way
The compiler is always looking for xcom.A and not A
cd xcom
javac A.java
SCJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Punit Singh wrote:
Abhi vijay wrote:
One more doubt,
javac -classpath xcom:. B.java ( current directory is test) what does this line imply?
This imply find B.java in xcom directory or in current directory, but there is no B.java in xcom directory as it is xcom/B.java, and there is no B.java in current directory as it is actually xcom/B.java.
Abhi vijay wrote:javac xcom/B.java
current directory is test. classpath is/foo. I think this allows B.java to compile?
SCJP 6
Sachin Adat wrote:
Punit Singh wrote:
Abhi vijay wrote:
One more doubt,
javac -classpath xcom:. B.java ( current directory is test) what does this line imply?
This imply find B.java in xcom directory or in current directory, but there is no B.java in xcom directory as it is xcom/B.java, and there is no B.java in current directory as it is actually xcom/B.java.
I guess you are wrong here Punit.
B.java is in xcom directory.
-classpath is for finding class files not java files,
So in the above case, javac first tries to find B.java in test directory which it is unable to find.
classpath is set to xcom and .
Had it found B.java it would have compiled because the classpath setting is correct for finding xcom.A when classpath is set to .
I think till the java file is compiled its still just the name so in this case B.java.
Had the command been javac -classpath xcom:. xcom/B.java(with current directory test), this could also have been a valid answer.
SCJP 6
Ankit Garg wrote:well you can compile a .java file even if it is not in the correct folder hierarchy. The javac command will put it into the correct hierarchy in that case. Suppose I have this class
package my.package;
class MyClass{}
Now if I put it under directory test and compile it from test directory, the MyClass.class file will go into the directory test/my/package.
SCJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abhi vijay wrote:
One more doubt,
javac -classpath xcom:. B.java ( current directory is test) what does this line imply?
SCJP 6
Sachin Adat wrote:
-classpath is for finding class files not java files,
So in the above case, javac first tries to find B.java in test directory which it is unable to find.
classpath is set to xcom and .
Had it found B.java it would have compiled because the classpath setting is correct for finding xcom.A when classpath is set to .
I think till the java file is compiled its still just the name so in this case B.java.
Had the command been javac -classpath xcom:. xcom/B.java(with current directory test), this could also have been a valid answer.
4. cannot find A.class
Abhi vijay wrote:javac -classpath xcom : . B.java.
when this line is invoked, the compiler searches for B.java in xcom directory, it finds it but cannot find xcom.A.
Abhi vijay wrote:javac xcom/B.java
current directory is test. classpath is/foo. I think this allows B.java to compile?
Sachin Adat wrote:also....
Abhi vijay wrote:javac xcom/B.java
current directory is test. classpath is/foo. I think this allows B.java to compile?
No, this will not be able to find A.class
test has to be in classpath.
SCJP 6
Abhi vijay wrote:javac -classpath xcom : . B.java.
when this line is invoked, the compiler searches for B.java in xcom directory, it finds it but cannot find xcom.A.
So now the classpath is set to (.), that is the test directory, here xcom.A is found but B.java cannot be found. So fails.
Now when I change
javac -classpath xcom : . xcom/B.java.
when this line is invoked, the compiler searches for B.java in xcom directory, it finds it but cannot find xcom.A.
then So now the classpath is set to (.), that is the test directory, here beacuse of the sub-directory xcom/B.java, the compilation suceeds.
This is waht I have gathered from Sachin and Punit's posts.
Am I right,???![]()
SCJP 6
Every plan is a little cooler if you have a blimp. And a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|