File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertion problem?" Watch "Assertion problem?" New topic
Author

Assertion problem?

Dan Coo
Greenhorn

Joined: Nov 10, 2002
Posts: 13
Hi all I've come across this question in a mock exam and I can't understand the answer, could somebody help please?
public class Assertification {
public static void main(String args[]){
assert args.length == 0;
}
}
Which of the following conditions must be true to throw an AssertionError?
a) The args array must have exactly zero elements.
b) The args array must have one or more elements.
The answer is (a), but doesn't that make the condition true. Shouldn't the condition be false to throw an AssertionError?
Ben Ritchie
Ranch Hand

Joined: Nov 18, 2002
Posts: 98
I've seen this before in Heller & Roberts 1.4 book - is the code fragment a shortened version of that question? The H&R answer is a typo.
(edited)the assert will throw an AssertionError only if args.length > 0 so the answer is (b) - it is in the errata on the sybex website
[ November 28, 2002: Message edited by: Ben Ritchie ]

SCJP1.4, SCJD, SCEA (in progress)
Dan Coo
Greenhorn

Joined: Nov 10, 2002
Posts: 13
Thanks Ben, I've been going over this for days, it is from the Heller and Roberts "Complete Java 2 Certification Study Guide". Thanks again.
Ben Ritchie
Ranch Hand

Joined: Nov 18, 2002
Posts: 98
Confused me too...
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
It's always best with any technical book to check the errata for the book. This is a pain but it's the 1st thing I usually do with a tech book because so many of them are rushed out and even if they are not it can be very difficult fot the authors/publishers to be 100% correct when so many details are covered.
Happy trails


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
anushree ari
Ranch Hand

Joined: Sep 30, 2002
Posts: 98
but ben, the typo is args.length>0 will throw assertion error, but the ans is a) contrast, what is exact result,


anushree
Ben Ritchie
Ranch Hand

Joined: Nov 18, 2002
Posts: 98
Whoops ... must read before I post...
Edited
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Assertion problem?