Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
muskaan gaffor
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alex!!!

regards,
Mussy!!!
 
muskaan gaffor
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alex!!!

regards,
Mussy!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic