Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question related to self test question in SCJP (Sierra/Bates) Java 6 book

 
John Cochrane
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've just gone through the test questions for chapter 10 (Development) and don't understand the answer given.

It says that A is correct and C is not and I don't understand the difference. Why you can use the -classpath MyJar.jar in the javac invocation yet it's not allowed in the java invocation (Answer C)? Also, how does the java GetJar call in answer A find MyApp.Foo with a classpath specified?

Regards,
John
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should post the question here. OR should have mentioned the question number. I had to go through all the question to find the actual question.
May be thats the reason , this post was unanswered for such a long time.

Why option A is correct,

When the classpath is not set in the command line or if the CLASSPATH environment variable is not set, then the classpath point to current directory.
For more calrification , check these links.

http://java.sun.com/javase/6/docs/technotes/tools/windows/javac.html
http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html

The reason why option C is wrong is because GetJar.class is not reachable.
The command should be java -classpath MyJar.jar;. GetJar
Note the classpath is only pointing to test/*.jar but not to test/.....


 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
Please Search First
I got a minimum of 2 posts discussing this, here and here.
how does the java GetJar call in answer A find MyApp.Foo with a classpath specified

So I guess there is no answer to it......there should be a 5th option- None of the above...........I guess
 
John Cochrane
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Thanks for the response and sorry for not putting the question number in the original post.

I'm happy now that I can see I'm not going crazy and the question was wrong :-)

Regards,
John
 
Kedar Nath
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does that mean that option A is wrong???
The link shows that classpath include current directory .
So it should work right ???
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kedar Nath wrote:So does that mean that option A is wrong???
The link shows that classpath include current directory .
So it should work right ???

I guess yes ....... it is wrong.
Kedar Nath wrote:The link shows that classpath include current directory .
So it should work right ???

No
You can see in the code that in GetJar, you are neither importing package myApp nor mentioning class Foo as myApp.Foo

 
Kedar Nath
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K& B scjp6


3. public class GetJar {
4. public static void main(String[] args) {
5. System.out.println(myApp.Foo.d);
6. }
7. }



Surprising ! ! !
This is what i i have in my e-book myApp.Foo.d
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kedar Nath wrote:Surprising ! ! !
This is what i i have in my e-book myApp.Foo.d

Now, that's really surprising... because I have Foo.d in my e-book. Will check the hardcopy and tell tomorrow.
When did you buy the book, from where, has a new edition come out???

 
Kedar Nath
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it is this myApp.Foo.d, then its right. Isn't it.

Actually it downloaded from some site... illegal copy But with right ansewers i guess
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even i have it as myApp.Foo.d

 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kedar Nath wrote:Actually it downloaded from some site... illegal copy But with right ansewers i guess

This is the reason why sometimes I think piracy is not that bad.........
You buy and you have problem, and you download it and that has no problems.......... :roll:
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Tharakan wrote:Even i have it as myApp.Foo.d

Now this is really strange.......
James you can even copy and paste, mine is secured......cant even copy and paste..........
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Adat wrote:
James Tharakan wrote:Even i have it as myApp.Foo.d

Now this is really strange.......
James you can even copy and paste, mine is secured......cant even copy and paste..........


For this, i got only one thing to say....(which you said)

This is the reason why sometimes I think piracy is not that bad.........
 
Sachin Adat
Ranch Hand
Posts: 213
 
Kedar Nath
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So according to this statement, myApp.Foo.d
the program is correct ,RIGHT
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kedar Nath you must not use illegal copies of books. It is unethical in addition to being illegal. And anyone who has a legal copy of the book knows that this is probably an error in the book which Bert is looking after and soon an errata will be published in this regard...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic