File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enabling Assertions

 
Arnab Saha
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arnab Saha
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disabled. They are only enabled if explicitly mentioned.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic