my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Maste Exam Question on classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B Maste Exam Question on classpath" Watch "K&B Maste Exam Question on classpath" New topic
Author

K&B Maste Exam Question on classpath

Siri Naray
Ranch Hand

Joined: May 19, 2006
Posts: 105
Given that the MusicPlayer project is on a Unix system and consists of the following files
/mp/classes/MusicPlayer.java
/mp/classes/player/MusicPlayer.class
/mp/jars/mp.jar

Inside mp.jar file structure is
player/MusicPlayer.java
player/MusicPlayer.class

you are currently in the directory
/mp
and the CLASSPATH is set to
/mp/jars

What command(s) can you use to invoke the class player MusicPlayer?

Correct Answer:
A. java -cp classes player.MusicPlayer
B. java -cp /mp/jars/mp.jar player.MusicPlayer


According to the K&B book Pg 768
"When searching for class files, the java and javac commands don't search the current directory by default.

Then how can answer A be correct?
According to what I understand the answer should be

java -cp classes/Player Player.MusicPlayer

because with this command the classes directory will not be searched where as Player will be searched and there we find the required .class file.

Can anyone please explain. I find similar questions in K&B which are really confusing me.


If you worry you cannot work... If you work you need not worry
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Well I checked both are working fine.
See the following:


My Directory structures are:

C:/threadpool/ All the java files
C:/threadpool/threadpool/All the classes
C:/threadpool/threadpool.jar

All the java files has following first line :
package threadpool;
[ September 02, 2008: Message edited by: Sunny Jain ]

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Puneet Nahata
Greenhorn

Joined: Aug 30, 2008
Posts: 9
Originally posted by Sirisha Ghatty:

"When searching for class files, the java and javac commands don't search the current directory by default.



First Sentence says: while searching for class files.
The class here is MusicPlayer.class, which you are explicitly providing in compile option: java -cp classes player.MusicPlayer

Rest is all folder navigation.


do not anger the GODS.
Siri Naray
Ranch Hand

Joined: May 19, 2006
Posts: 105
Hi Puneet,
Do you mean to say since Plyer.MusicPlayer is explicitly specified that option is right?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B Maste Exam Question on classpath
 
Similar Threads
Question classpath
Mock question on classpath
Another Error in Master Exam...
Possibly misleading Master Exam question
Classpaths