• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I think the answer should be "B" ? K&B SCJP5 errata

 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help me out here. If you are in the xcom directory and the classpath is set to classpath . ,
then when you execute the javac command in the xcom directory, javac should find A.class. Can you tell me what I'm missing?

Thanks,
Harry


5. Given the default classpath:
/foo

And this directory structure:
______ foo
________|
________test
__________|
__________xcom
______________|--A.class
______________|--B.java

And these two files:




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:
® 3 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. (Objective 7.2)
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try to Search First as someone else might have had the same problem earlier so it might be already solved. If you search using xcom, then you'll find a lot of discussions like the following

http://www.coderanch.com/t/449709/Programmer-Certification-SCJP/certification/classpath-K-B
http://www.coderanch.com/t/431008/Programmer-Certification-SCJP/certification/K-B-chapter-Q-classpath
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is nothing wrong in the solution. just try to implement the structure in your system & check the options.

avi sinha
 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the feedback, Ankit and Avi. I've figured out what I was missing when I looked at the code snippets.



If /foo/test/xcom/ contains A.class and B.java, then the following command line instructions are correct.

>cd /foo/test
>javac -classpath . xcom/B.java



if /foo/test/xcom/ contains A.class and B.java, then the following command line instructions are correct.

>cd /foo/test/xcom
>javac -classpath . B.java

I didnt' take the statements into account.

Thanks,
Harry

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic