Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Mock question on classpath

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any help is appreciated! have the exam tomorrow!
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Raphael,

can you please make it more clear.

Mamta Sharma
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please wht cp.jar is there in the anwer H
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic