This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes classpath K&B problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "classpath K&B problem" Watch "classpath K&B problem" New topic
Author

classpath K&B problem

Akanksha Joy
Greenhorn

Joined: Jun 05, 2009
Posts: 17

Source: SCJP K&B

I have not understood why we cannot move to xcom folder and access A.class file there. The fully qualified name of the A.class file is 'xcom.A' and B want to have access to A.class thats y? What about the other parts......Please explain with reason...
Alexander Danilou
Greenhorn

Joined: May 08, 2009
Posts: 28
Important point to remember that classpath should point to super-directory of the package (please see K%B 6 page 804 last paragraph). So, you should be either in super-directory, or test in this case, OR you can also use absolute path, but this option is not provided here.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Well since the fully qualified name of the class is xcom.A, so you must access it from the parent directory of xcom (or the parent directory must be in the classpath). If you try to access A from xcom directory, then it will try to find a folder named xcom in the xcom directory and it will not be found.

So the deal is, if the package ab.cd has a class MyClass and you have this directory structure folder/ab/cd, then you must move to folder directory and use ab.cd.MyClass to access the class. You cannot access MyClass if you move to ab directory or cd directory...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

This exact same question has been discussed more than once before. Try searching the forums for "xcom" and you'll find the older discussions.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath K&B problem
 
Similar Threads
Classpath
K&B Chapter 10, Self test doubt
Ch. 10 Development question
Classpath - Question 1
question from Kathy Seirra book classpaths