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 assert question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assert question" Watch "assert question" New topic
Author

assert question

patrick avery
Ranch Hand

Joined: Sep 12, 2008
Posts: 46
In the Master Exam I came across a question with some code containing 2 assert statements. The text of the question did not reference the assert statements and did not indicate that asserts had been enabled...it just asked "What is the result?"

2 questions:

1 - for the exam if the code contains assert statements but nothing is said about whether or not they are enabled should we assume that they are not?

2 - if asserts are not enabled does this mean they will not be executed or only that they will execute but not cause an assert exception?


SCJA 96%
SCJP 6 88%
skipping SCJD to work on passing SCWCD
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Hi Patrick,

1. In Java 1.6 assertions are enabled by default at compile time, but at runtime they are disabled unless you enable them explicitly.

2. When you don't enable assertions at the java command line that means the JVM will bypass assertion code (it is as if it hadn't been coded.)
[ December 30, 2008: Message edited by: Ruben Soto ]

All code in my posts, unless a source is explicitly mentioned, is my own.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: assert question