• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

assertions in java 6

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there ,
i was wondering what the output should be for the following code ,
public static void main(String[] args) {
// TODO Auto-generated method stub
int age =18;


assert(age < 18);
System.out.println("hello here......................");
}
surely an assertion error and the "hello here" shouldn't be displayed ..i am sorry but this dosent happen when i run it on eclipse indigo and i use jdk 1.6.0_27.can anyone figure out where's the bug?
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mrs nair wrote:hi there ,
i was wondering what the output should be for the following code ,
public static void main(String[] args) {
// TODO Auto-generated method stub
int age =18;


assert(age < 18);
System.out.println("hello here......................");
}
surely an assertion error and the "hello here" shouldn't be displayed ..i am sorry but this dosent happen when i run it on eclipse indigo and i use jdk 1.6.0_27.can anyone figure out where's the bug?



Hello Mrs Nair... Assertions are disabled by default, if you intend to enable assertions in other for the above code to throw an assertion error, you can simply use the command lines and navigate to the .class file
or the packge directory and run the class with the -ea (enable assertions) flag, i.e 'java -ea com.xxx.YourClass'...

HTH

Ikpefua
 
Ranch Hand
Posts: 58
Eclipse IDE C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To enable assertion on Eclipse, select from Menu Bar,Run ->Run Configuration->Arguments tab.Now type -ea in VM arguments and click on Apply.Now you'll get the AssertionError when you run. I am using Mac OS X 10.5.8.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic