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 ]
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.
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?