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 Enabling 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 "Enabling Assertions" Watch "Enabling Assertions" New topic
Author

Enabling Assertions

Arnab Saha
Greenhorn

Joined: Nov 08, 2005
Posts: 10
What should be the o/p:
public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): �assertion failed�;
System.out.println(�finished�);
}
}
Ans: Assertion thrown,or "finished".
If nothing is mentioned should we consider Assertion is disabled.
Jon Lee
Ranch Hand

Joined: Mar 04, 2005
Posts: 134
For java 1.5, I found assertions are disabled at run-time. You have to use switch '-ea' to enable assertions at run-time.

But at compile time, the assertions is treated as a keyword by default.


SCJP 5.0 - 98% (2007)<br />SCWCD 1.4 - 97% (2007)
Arnab Saha
Greenhorn

Joined: Nov 08, 2005
Posts: 10
I want to know that if during Test of SCJP 1.4 if nothing is mentioned
what should we consider - Assertions enabled or Disabled.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

Disabled. They are only enabled if explicitly mentioned.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enabling Assertions