Share on Google+Share on Google+

raja kiran kumar
1 Answer(s)      8 years ago
Posted in : Java Beginners


View Answers

June 10, 2008 at 3:19 PM

Hi friend,

The assertion statement has two forms.

assert Expression1:Expression2;

The first one is a simpler form that takes a boolean expression as an argument. The expression is the one the programmer wishes to assert as true. If the assumption fails, the expression evaluates to be false which means the assertion failed. In case the expression succeeds the program continues normally.

The second form is the more descriptive one. The first argument takes a Boolean expression, while the second expression would be the resulting action to be taken if the assertion fails. The Expression2 should be a value and can also be a result of executing a function. The compiler would throw an error if the second expression returns a void value.


public class AssertionExample{

public static void main(String argv[]) throws IOException{
System.out.println("Enter your marital status: ");
int c =;
switch ((char) c) {
case 's':
case 'S': System.out.println("Single");
case 'm':
case 'M': System.out.println("Married");
case 'd':
case 'D': System.out.println("Divorced");
default: assert !true : "Invalid Option"; break;

// default: Assertion.assert(!true, "Invalid Option");
// break;


Read for more information.


Related Tutorials/Questions & Answers:
assertions - Java Beginners
assertions  can you explain me how and when assertions are usefull with an example.. Thanks in advance  Hi friend, The assertion statement has two forms. assertExpression1; assert Expression1:Expression2
Assertion in java
program! In another words we can say that assertions ensures the program... to guide the programmer. Assertions are of two types: 1) Preconditions 2) Postconditions. Preconditions are the assertions which invokes when a method
assertion in java
! In another words we can say that assertions ensures the program validity by catching... the programmer. Assertions are of two types: 1) Preconditions 2) Postconditions. Preconditions are the assertions which invokes when a method is invoked
Assertion in java
can say that assertions ensures the program validity by catching exceptions
Assertion in Java
't be a void method. Compiling Code containing assertions Compiler accept your code having assertions, if you compile it as follows... By default assertions are disabled at runtime. You can enable assertion at runtime
EclipsePro Test
cases. Create new test cases by entering arguments and assertions. See
Beginners Java Tutorials - Installing JDK
assertions -da[:<packagename>...|:<classname>... assertions -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable system
Java Assertion
assertions. How to Enable and Disable Assertion Assertion are disabled at run-time... or enable assertions is used to enable assertion during run-time execution
and assertions), but most of the unit test is created automatically. In addition
assert In Java
, and invariants of a class. Where To Use Assertions Assertion is used in computer
Core Java Jobs at Rose India
be proficient in I/O Package Candidate must be proficient in Assertions
ALL command - SQL
[:...|:] -enableassertions[:...|:] enable assertions... assertions -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable
what is the difference between jdk 1.4 and 1.5 and 1.6
various input streams and buffers. - Assertions - StringBuilder class (in java.lang
A - Java Glossary
A - Java Glossary       Java Assertions In Java 1.4, Assertion is a keyword that is represented by a boolean expression and enables you to test your assumptions about your
Various Commands that are used in java are given below
;] enableassertions[:<packagename>...|:<classname>] enable assertions da...;packagename>...|:<classname>] disable assertions esa | -enablesystemassertions enable system assertions dsa | -disablesystemassertions disable
What is Solex ?
the attachment of assertions to responses in order to validate a scenario during
Java Keywords
with assertions . If the condition is false, the Java runtime system throws an AssertionError
Using JMeter for a Simple Test
groups, listeners, assertions, sample generating controllers, logic controllers etc
What are the level in Jboss 5 application server to deploy the application
streams and buffers. - Assertions - StringBuilder class (in java.lang package
Java Training and Tutorials, Core Java Training
Assertions Errors in Integer Arithmetic
HttpUnit Test
. These assertions are taken from the Junit API.  assertEquals
Java Certification Books
, converting, casting, flow control, assertions, exceptions, objects, classes, threads
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null