wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assertions in java 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assertions in java 6" Watch "assertions in java 6" New topic
Author

assertions in java 6

mrs nair
Greenhorn

Joined: Aug 28, 2011
Posts: 2
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?
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

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


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Sebanti Sanyal
Ranch Hand

Joined: Nov 07, 2011
Posts: 58

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assertions in java 6