• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Do we need to provide classpath for jar file with java command if jar file is in current directory?

 
Ranch Hand
Posts: 37
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I consider the example from SCJP Sun Certified Programmer for Java 6 Study Guide by Katherine Sierra and Bert Bates (K&B) Page number 817, Chapter 10 and Question no 11. The correct answer according to the book is option A.

The second command is java GetJar, my quesion is how does it find the MyJar.jar without providing classpath or does it use the current directory as used for GetJar.class but it does not work.

11. Given the following directory structure:
test-|
       |- GetJar.java
       |
       |- myApp-|
                      |-Foo.java
And given the contents of GetJar.java and Foo.java:
3. public class GetJar {
4. public static void main(String[] args) {
5. System.out.println(myApp.Foo.d);
6. }
7. }

3. package myApp;
4. public class Foo { public static int d = 8; }

If the current directory is "test", and myApp/Foo.class is placed in a JAR file called MyJar.jar
located in test, which set(s) of commands will compile GetJar.java and produce the output 8?
(Choose all that apply.)

Answer:
A.
javac -classpath MyJar.jar GetJar.java
java GetJar


Thank you.

 
Greenhorn
Posts: 24
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an error in the question. You indeed have the provide the jar in a classpath. See this topic for more detail.
 
Matloob Hussain
Ranch Hand
Posts: 37
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jack.................
 
reply
    Bookmark Topic Watch Topic
  • New Topic