my dog learned polymorphism*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 19541
    
  16

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Enabling Assertions
 
Similar Threads
Output of this code
Assertions mock exam question
on assertions
My problem wif Java questionssss
assert help