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 Using Assertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Using Assertion" Watch "Using Assertion" New topic
Author

Using Assertion

May Pat
Ranch Hand

Joined: Jul 01, 2002
Posts: 32
Can assertion be enabled for multiple classes? I.e. If my application will access class A, B, and C which may or may not be in the same package and I want to enable assertion on class A and B, but not C. :roll:


May P.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Yes. At runtime, when you invoke your application, just use the -ea:qualified.className syntax for each class that you want assertions turned on for.
See Enabling and Disabling Assertions


"JavaRanch, where the deer and the Certified play" - David O'Meara
May Pat
Ranch Hand

Joined: Jul 01, 2002
Posts: 32
Thank you very much, Cindy.
David Brafford
Ranch Hand

Joined: Feb 11, 2001
Posts: 91
And things get interesting when Class B
inherits from Class A and Class A has
assertions enabled, and Class B does not ( or
vice versa ).
--------------------------------------
Considering the Certified Java Programmer Exam?
Get JCertify!
http://www.enterprisedeveloper.com/jcertify
For exam 310-025 and 310-035
May Pat
Ranch Hand

Joined: Jul 01, 2002
Posts: 32
Thank you David for pointing that out.
Another question. I read about assertion in the book, JDK 1.4 Tutorial by Gregory M Travis. He has an example where he does something like"java -ea kg0 MyProgram" to enable assertion for the package pkg0. He leaves out ... after pkg0 name and the result is that assertion is disabled. I tried that myself and found the same result and no complaint from JRE. Is this because it thinks that I try to enable assertion for a class name, pkg0? And since there's no such class, the enable does not have effect. And seems like, it doesn't check for existence of the class either.
Thanks a bunch.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Yes. The "..." is the hint to the JVM that the name you gave it is a package name instead of a class name.
Don't you just LOVE the -ea:... option . "Just check stuff in THIS directory".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Assertion