File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B Maste Exam Question on classpath

 
Siri Naray
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Puneet Nahata
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Siri Naray
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic