aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock question on classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock question on classpath" Watch "Mock question on classpath" New topic
Author

Mock question on classpath

Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 118
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 ]

SCJP 6 83%
Working on SCWCD/OCPJWCD
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 118
Any help is appreciated! have the exam tomorrow!
Raphael Rabadan
Ranch Hand

Joined: Jul 05, 2008
Posts: 141
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 ]

SCJP Java 6 (98%) - Story, SCJA (88%) - Story
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 118
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

Joined: Jun 03, 2008
Posts: 25
Hey Raphael,

can you please make it more clear.

Mamta Sharma
varinder mahajan
Ranch Hand

Joined: Jun 11, 2008
Posts: 47
please wht cp.jar is there in the anwer H


Beat the world,if you can.......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock question on classpath
 
Similar Threads
Another Error in Master Exam...
Question classpath
Mock Exam Question Doubt, 36: 74 from K&B CD
Possibly misleading Master Exam question
Classpaths