Search code examples
javascjp

A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system


I need help understanding this problem

The correct answer is 'C'

A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: java games.cards.Poker What allows the user to do this?

A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java

B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jar

C. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar

D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java

E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/*.jar

F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker. jar


Solution

  • The command means, inside the Poker.jar there are directories for games/cards/Poker.java... Don't confuse this with the paths needed to include the jar itself.

    java games.cards.Poker
    

    A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java

    does not work because setting the classpath as /stuff/java sets the path to your directories/files but it will not go a step further to include your jar (and the classes inside it).


    B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jar

    does not work because it is not the correct syntax for including all the jar files in one directory. (Java 6 and higher) It should be /stuff/java/*


    D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java

    same as A, including a higher level path does not include all the paths inside of it.


    E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/*.jar

    same as B and A, incorrect syntax + won't include all the paths


    F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jar

    classpath here is pointing to the wrong directory for the jar


    C. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar

    This is finally finding the jar, which is in the correct directory.


    Resources

    http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

    http://en.wikipedia.org/wiki/Classpath_(Java)