aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes k&B -chapter 10 Question # 10 -  kindly explain me 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "k&B -chapter 10 Question # 10 -  kindly explain me" Watch "k&B -chapter 10 Question # 10 -  kindly explain me" New topic
Author

k&B -chapter 10 Question # 10 - kindly explain me

muskaan gaffor
Ranch Hand

Joined: May 19, 2006
Posts: 50
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
javac -classpath /foo/bar/baz/bing:/foo/bar MyClass.java
Which version will be used by javac?
A. /foo/MyClass.java
B. /foo/bar/MyClass.java
C. /foo/bar/baz/MyClass.java
D. /foo/bar/baz/bing/MyClass.java
E. The result is not predictable.
Answer:
D is correct. A -classpath included with a javac invocation overrides a system classpath.
When javac is using any classpath, it reads the classpath from left to right, and uses the
first match it finds.
A, B, C, and E are incorrect based on the above.

My doubt is::


if the command line is from from /foo

javac -classpath /foo/bar:/foo/bar/baz/bing MyClass.java
will the answer is B???

kindly correct me...i got confused a lot with this concept!!!
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

Originally posted by muskaan gaffor:
javac -classpath /foo/bar/baz/bing:/foo/bar MyClass.java
Which version will be used by javac?
A. /foo/MyClass.java
B. /foo/bar/MyClass.java
C. /foo/bar/baz/MyClass.java
D. /foo/bar/baz/bing/MyClass.java
E. The result is not predictable.


According to your specified classpath, the first directory the compiler will look in is :/foo/bar/baz/bing.Is there a MyClass.java there ? Yes, answer D




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


According to your specified classpath, the first directory the compiler will look in is :/foo/bar.Is there a MyClass.java there ? Yes, the answer B

So you were right.

Regards,
Alex
[ January 23, 2008: Message edited by: Alex Belisle Turcot ]
muskaan gaffor
Ranch Hand

Joined: May 19, 2006
Posts: 50
Thanks Alex!!!

regards,
Mussy!!!
muskaan gaffor
Ranch Hand

Joined: May 19, 2006
Posts: 50
Thanks Alex!!!

regards,
Mussy!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: k&B -chapter 10 Question # 10 - kindly explain me