Ans:With assertions enabled it prints 210210 followed by an AssertionError message. With assertions disabled it prints 210210-1
--really need someone to explain it to me.can't understand. and if i want to complie,what's command i need to input
How to fix the following error to make the program work? Asser.java:10: warning: as of release 1.4, assert is a keyword, and may not be used as an identifier assert j == 2; ^ Asser.java:10: ';' expected assert j == 2;
Thanks a lot.
Joined: May 30, 2005
Hi Dan, If u want to use assertion u have to put javac -source 1.4 <Source File Name>.
For Execution java -ea <Class Name> or java -enableassertions <Class Name>
Syntax for Assertion is: assert <boolean expression>:expression If the boolean expression is false and the assertions enabled,expression value is passed to Assertion Error Constructor.This value is converted into string format when assertion fails.
Hope u understood. Reg Vasanth
SCJP 1.4(85%)<br />SCWCD 1.4(79%)
Joined: Oct 24, 2000
More on assertions and when to use them in Chapter 5 of "Complete Java 2 Certification".
Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".
Joined: Nov 29, 2002
I only have this one JAVA 2 sun certified programmer & developer
210210 get printed for the values of i from 5 to 0 .
When i=-1 , it goes into the default case of the switch statement. and it fails at the assertion ie assert i==2 and hence it gives the assertionError (when assertion are enabled ) and thus terminates .
when we disable assertion the assert command is not executed and system print the -1 value of the i.