Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another Error in Master Exam...

 
Marcus Moreno
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"!

Cheers,

Marcus
 
Abel R Gonzalez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Hi Abel,

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.
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Abel R Gonzalez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Ruben,

I had missed the point that: / = C:\

/ - UNIX root directory
C:\ - Windows most common root directory
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abel Gonzalez wrote:Thanks a lot Ruben,

I had missed the point that: / = C:\

/ - UNIX root directory
C:\ - Windows most common root directory

No problem, Abel! Yes, the K&B book normally follows UNIX conventions, and like Ankit said, the questions in the exam will also assume Linux.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic