aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question related to self test question in SCJP (Sierra/Bates) Java 6 book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question related to self test question in SCJP (Sierra/Bates) Java 6 book" Watch "Question related to self test question in SCJP (Sierra/Bates) Java 6 book" New topic
Author

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

John Cochrane
Greenhorn

Joined: Jan 21, 2005
Posts: 8
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

Joined: Aug 29, 2008
Posts: 580

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/.....



SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
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


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
John Cochrane
Greenhorn

Joined: Jan 21, 2005
Posts: 8
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

Joined: Sep 02, 2008
Posts: 53
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

Joined: Sep 03, 2007
Posts: 213
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

Joined: Sep 02, 2008
Posts: 53
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

Joined: Sep 03, 2007
Posts: 213
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

Joined: Sep 02, 2008
Posts: 53
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

Joined: Aug 29, 2008
Posts: 580

Even i have it as myApp.Foo.d

Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
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

Joined: Sep 03, 2007
Posts: 213
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

Joined: Aug 29, 2008
Posts: 580

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

Joined: Sep 03, 2007
Posts: 213
Kedar Nath
Ranch Hand

Joined: Sep 02, 2008
Posts: 53
So according to this statement, myApp.Foo.d
the program is correct ,RIGHT
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question related to self test question in SCJP (Sierra/Bates) Java 6 book