• 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

When assertions are executed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question from the ePractice exams for 310-055 purchased directly from Sun Microsystems.

Given:



Which is true?

A - An assertion error will occur at runtime.
B - The command-line invocation java -ea TestAssert will produce no error and the output "more info ".
C - The command-line invocation java -ea TestAssert will produce no error and the output "after assert ".
D - The command-line invocation java -ea TestAssert will produce no error and the output "more info after assert ".
E - The command-line invocation java -ea TestAssert will produce no error and the output "after assert more info ".

Sun's answer is:
Option A is correct. The command-line enables assertions, and more info is added to the stack trace before the program ends at line 3 with an AssertionError.

I disagree. Assertions are disabled by default at runtime. The question did not provide the command-line being used. I think the correct answer should be (which is not one of the options provided):
The command-line invocation java -ea TestAssert will produce an assertion error and the output "more info ".

Can someone please confirm?

Thank you!
Bonnie
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree whit you my friend.
This question is little misleading.
But let me ask you something.
When this error will occur ?


The command-line invocation java -ea TestAssert will produce an assertion error and the output "more info ".


At runtime or during compiling time ?
Of course at runtime.
Then first logical answer is A !

Dejan.
 
Bon Thanh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, Dejan, if you put it that way, then I agree that the logical answer out of the answers provided would be A.
Thanks!
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option A is the only possible answer.

Without "-ea" option, the assertion error, if any, is suppressed.
But with "-ea" it is displayed on the console.



Hence output is different with different option of executing the code.
But in any case choice A is always going to happen.

So Option A is correct answer.
 
Bon Thanh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting. I thought disabling assertions meant that they weren't even processed. Since when assertions are enabled, your application's performance is affected.
So you're saying that enabling or disabling assertions just means whether or not they are displayed on the console? But assertion statements are always processed?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic