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 Having trouble understanding assertions:See this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Having trouble understanding assertions:See this code" Watch "Having trouble understanding assertions:See this code" New topic

Having trouble understanding assertions:See this code

Chiran Mathur
Ranch Hand

Joined: Feb 07, 2001
Posts: 63
I have the following piece of code:
public class assertUse{
public void m1(int value)
assert 0<=value;
public static void main(String[] args){
assertUse aU=new assertUse();
Shouldn't it throw an erro when -1 is passed to m1(). When I compile it the program gives the following output:
I am not sure why it is not throwing an asertioerror in case of -1. Can somebody help?
Brian Quate

Joined: Jan 24, 2003
Posts: 2
Did you enable assertions when you ran the code?
java -ea assertUse
By default they are disabled.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Check the JavaRanch newsletter. I think it was in September that we had two articles on using assertions.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Having trouble understanding assertions:See this code