• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Ch10:Development

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a query regarding Ch10 self test Q10. It states there are three version of MyClass.java
in three diff folder namely

As per what i understand javac looks for .java file in the current directory by default unless the file path is specified. In above case there is no MyClass file in /foo directory so java compiler should not be able to find the file. But the answer says that version MyClass.java in
/foo/bar/baz/bing will be compiled.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got bit by this question too - I had the partially updated version of the question : where javac was changed to java - but still the question was confusing. This below seems to be the complete fix to the question (note the change from javac to java and .java to .class).It would be great if they could update the errata for this question.

----------------
If three versions of MyClass.class exist on a file system:

Version 1 is in /foo/bar
Version 2 is in /foo/bar/baz
Version 3 is in /foo/bar/baz/bing

And the system's classpath includes:

/foo/bar/baz

And this command line is invoked from /foo

java -classpath /foo/bar/baz/bing:/foo/bar MyClass

Which version will be used by java?
A. /foo/MyClass.class
B. /foo/bar/MyClass.class
C. /foo/bar/baz/MyClass.class
D. /foo/bar/baz/bing/MyClass.class
E. The result is not predictable.
----------------

I found the answer to this from this topic
https://coderanch.com/t/260568/java-programmer-SCJP/certification/SCJP-topic-Ch
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The default path is overridden by the classpath at the command line.
classpaths are searched from left to right.
Once a MyClass.class file is found ,then that is executed

So from the command line, the only two places it will look for class is
/foo/bar/baz/bing and /foo/bar

It finds in /foo/bar/baz/bing

HEnce answer is D and hope i am right
 
V Black
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep D is correct - which becomes clear once you are working with a completely corrected version of the question.
 
reply
    Bookmark Topic Watch Topic
  • New Topic