• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

https://coderanch.com/t/449709/Programmer-Certification-SCJP/certification/classpath-K-B
https://coderanch.com/t/431008/Programmer-Certification-SCJP/certification/K-B-chapter-Q-classpath
 
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic