Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java command: classpath or not classpath?

 
Roy Miro
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In K&B's book, chapter 10 Question 11

And given the contents o fGetJar.java and Foo.java:


Current directory: test
myApp/Foo.class is placed in MyJar .jar

The following commands to compile and run are:
javac -classpath MyJar.jar GetJar.java
java GetJar
( The output is 8)


Now in question 12:



And given the contents of GoDeep.java and Foo.java:


And MyJar.jar contains the following entry:
myApp/Foo.class
If the current directory is x, which commands will successfully execute GoDeep.class and
produce the output 8? (Choose all that apply.)

A wrong answer is :
java GoDeep


My question: why in q11 we did not have to specify a classpath to java command while in q12 we had to?


Thanks for your time.
 
Roy Miro
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the links.
I had searched but maybe not deeply enough

Nice day!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic