Question from Master Exam from the K&B SCJP book / from the cd from the book..
Question Given that the MusicPlayer project is on a UNIX system and consists of the following files: /mp/player/MusicPlayer.java /mp/classes/player/MusicPlayer.class /mp/jars/mp.jar Inside mp.jar file the structure is: player/MusicPlayer.java player/MusicPlayer.class /mp and the CLASSPATH is set to /mp/jars What command(s) can you use to invoke the class player.MusicPlayer? (Choose all that apply.) Correct Answer E: java -cp classes player.MusicPlayer H: java -cp /mp/jars/cp.jar player.MusicPlayer
H is wrong, because it says "cp.jar" - there is no "cp.jar but only a "mp.jar"!
Abel Gonzalez wrote:This question also raised my attention because of the -cp argument in option H. I can't try this on UNIX right now, but
java -cp \mp\jars\cp.jar player.MusicPlayer
won't work on Windows. However,
java -cp jars\cp.jar player.MusicPlayer
will, having mp as the current directory like the question specifies.
Is this one of those UNIX/Windows subtleties? I admit I'm not a UNIX hacker
Are you sure that the command doesn't work in Windows? If not, I think the problem is the root directory, which should probably be something like C:\ instead of \. Try and see if that works.
Also, I think the current directory is irrelevant in this case, since you are not adding the current directory explicitly to the classpath, and if you specify a classpath you must include the current directory explicitly in it, or it won't be used.
Ruben is right. The questions in the actual exam will assume Linux as the underlying operating system. So you'll have to think that way. The questions in the Master Exam is way way similar in pattern to the real exam that's why they also use linux style commands...