• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B Maste Exam Question on classpath

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Puneet,
Do you mean to say since Plyer.MusicPlayer is explicitly specified that option is right?
 
reply
    Bookmark Topic Watch Topic
  • New Topic