Question is as follows:
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
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? (Choose all that
apply.)
Correct Answer
E: java -cp classes player.MusicPlayer
H: java -cp /mp/jars/cp.jar player.MusicPlayer
OCPJP 6, OCMJD
Helen Ma wrote:Yes. You're right. It should be mp.jar instead of cp.jar.
I guess MusicPlayer is in declare in player package.
java -cp classes player.MusicPlayer is right because player.MusicPlayer is the fully qualified name of this class.
java executes .class file, not .java file.
On the other hand, javac compiles .java file to make a .class file.
java goes to classes path and find the MusicPlayer.class. Then, it executes this class file.
OCPJP 6, OCMJD
java -cp classes player.MusicPlayer is right because player.MusicPlayer is the fully qualified name of this class.
OCPJP 6, OCMJD
Glen Iris wrote:
java -cp classes player.MusicPlayer is right because player.MusicPlayer is the fully qualified name of this class.
I still do not see how this works. The default classpath is /mp/jars
in the jars directory, there is no directory named 'classes'.
Joanne
The classes directory would have to be a subdirectory of the current directory (i.e. /mp) which it is
OCPJP 6, OCMJD
Glen Iris wrote:From what I see, the classes directory referred to in your above quote will is the one contained within the JAR file. So is this acceptable to use without mentioning the actual JAR file?
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
Joanne
OCPJP 6, OCMJD
Glen Iris wrote:
The classpath is set to /mp/jars
If we use E "java -cp classes player.MusicPlayer " that means that we the make the classpath = "/mp/jars:classes"
1 - Is my above statement correct?
2 - If my above statement is correct, contained within "/mp/jars:classes" must be a directory named player containing a file named MusicPlayer.class. However the contents of "/mp/jars" is: mp.jar
and
there is no /classes directory relating to "/mp/jars:classes"
Helen Ma wrote:Regarding to 1. I think according to Joanne, if you set "java -cp classes", it means your class path is classes only, not /mp/jars.
Helen Ma wrote:Regarding to 2. I think if you do this "java -cp /mp/jars:classes" means your classpath is /mp/jars and classes. /mp/jars is the absolute directory,just like c:\mp\jars in Windows OS.
Helen Ma wrote:So, java will find MusicPlayer.class from /mp/jars. If it is not found, it will search through classes folder to find it.
Joanne
Don't get me started about those stupid light bulbs. |