Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock question on classpath

 
Milan Sutaria
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source: K&B MasterExam

/mp/plyer/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 in the directory /mp
and classpath is set to /mp/jars

What commands can you use to invoke the class MusicPlayer.class?
A) java player.MusicPlayer
B) java player/classes/MusicPlayer.class
C) java -cp player MusicPlayer
D) java -cp classes MusicPlayer
E) java -cp classes player.Musiclayer
F) java -cp /mp/classes/player MusicPlayer
G) java -cp jars/cp.jar MusicPlayer //EDITED a typo should be mp.jar
H) java -cp /mp/jars/cp.jar player.MusicPlayer //EDITED a typo should be mp.jar

correct answers given are E & H

can some one explain me? why F & G are wrong?
[ August 06, 2008: Message edited by: Milan Sutaria ]
 
Milan Sutaria
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help is appreciated! have the exam tomorrow!
 
Raphael Rabadan
Ranch Hand
Posts: 141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1st - The command to run the class should be the full qualified name, so its stand for player.MusicPlayer
2nd - We gotta have it on the classpath, the two ways you can get it is from jar, and from /mp/classes/

When you have a class in a package, the classpath you need to import wont use the package, because, like in this examples, when you use -cp /mp/classes and try to run player.MusicPlayer it will try to find a /mp/classes/(directories of full qualified name)/nameOfClass.class in this case: /mp/classes/player/MusicPlayer.class. It's the same to the .jar, inside of it, it should have the structure of the full qualified name of the class, like it has.

Well, did i clarify or made it even more complicated?

EDIT: By the way, good luck on your test. After you do it, say to us how was your experience.

Kind Regards,
Raphael Rabadan
[ August 06, 2008: Message edited by: Raphael Rabadan ]
 
Milan Sutaria
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raphael for responding! Definitely i will post my experience out here. right now i am feeling nervous
But why won't this work ...
present directory is /mp
in option F) i am setting the classpath to /mp/classes/player and then i am invoking the MusicPlayer file

a similar thing i am doing in option G)

I didnot get your 1st point of fully qualified name ... could you explain it further?
 
Mamta Sharma
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Raphael,

can you please make it more clear.

Mamta Sharma
 
varinder mahajan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please wht cp.jar is there in the anwer H
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic