File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on enable system assertions 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 "Question on enable system assertions" Watch "Question on enable system assertions" New topic

Question on enable system assertions

Richard Vagner
Ranch Hand

Joined: Jun 26, 2001
Posts: 107
When do we need to have system assertions enabled? Can someone give me an example in which the system assertion is enabled?
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
If you have assertions in your source code, you must compile like this:
javac -source 1.4
or your assert statements will cause compilation errors.

To enable these assertions, you must also execute like this:
java -ea MyClass
Otherwise, the compiled assertions will not do anything at execution time.

Mike Gershman
SCJP 1.4, SCWCD in process
Richard Vagner
Ranch Hand

Joined: Jun 26, 2001
Posts: 107
Thanks Mike,

Actually, I am asking about "system assertions", which can be enabled by
java -esa

I want to know why we need it and an example will be great.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
From an SCJP perspective, you just need to know that -esa is entirely independent of -ea and -dsa is equally independent of -da and that these options control assertions in system classes. Full stop.

What are the "system classes" controlled by -esa? Classes not loaded by a classloader. I think that these are classes integral to the jvm itself.

Are there actually any assertions in these classes as part of j2sdk1.4? Not in any documentation or source libraries that I searched.

When would you use -esa? When software support asks you to, probably after adding some debugging code to trap a specific problem.

If you want more information contact Sun, if you have the contacts, or grab a developer at a Sun presentation.
marc weber

Joined: Aug 31, 2004
Posts: 11343

Note that in Java 1.5, no special flags are needed to compile with assertions.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Question on enable system assertions
Similar Threads
Assertions related
Exam doubt
Assertion - what are system classes?