Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Java General Java Assertions Tutorial

An assertion is a statement containing a boolean expression that is assumed to be true when the statement is executed. The system reports an AssertionError if the expression evaluates to false.

Tutorial Details:

Java Assertions

An assertion is a statement containing a boolean expression that is assumed to be true when the statement is executed. The system reports an AssertionError if the expression evaluates to false.

the assertion expression is true if a is negative. If a is positive, an AssertionError is thrown with the message "a is positive."

Assertions are disabled by default. To compile with assertions enabled, you need to use the source 1.4 flag:

javac -source 1.4 Test.java
To enable assertions at runtime, use the -enableassertions or -ea flags.

For selective disabling of assertions at runtime, use the -da or -disableassertions flags.

For enabling assertions in the system classes, use the -esa or -dsa flags. Assertions can also be enabled or disabled on a package basis.

Appropriate and inappropriate use of assertions
You can place an assertion at any location that you don't expect to be reached normally. Assertions can be used to validate the parameters passed to a private method. However, assertions should not be used to validate parameters passed to public methods because a public method must check its arguments regardless of whether assertions are enabled or not.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Java General Java Assertions Tutorial

View Tutorial:
Java General Java Assertions Tutorial

Related Tutorials:

iContract: Design by Contract in Java - JavaWorld February 2001
iContract: Design by Contract in Java - JavaWorld February 2001
 
Language improvements and models make great Java - JavaWorld
Language improvements and models make great Java - JavaWorld
 
J2SE 1.4 premieres Java's assertion capabilities, Part 1
J2SE 1.4 premieres Java's assertion capabilities, Part 1
 
J2SE 1.4 premieres Java's assertion capabilities, Part 2
J2SE 1.4 premieres Java's assertion capabilities, Part 2
 
Implement Design by Contract for Java using dynamic proxies
Implement Design by Contract for Java using dynamic proxies
 
The Java Web Services Tutorial
This tutorial is a beginner\'s guide to developing Web services and Web applications using the Java Web Services Developer Pack (Java WSDP).
 
The J2EE 1.4 Tutorial
The J2EE 1.4 Tutorial is a guide to developing enterprise applications for the Java 2 Platform, Enterprise Edition (J2EE) version 1.4. Here we cover all the things you need to know to make the best use of this tutorial.
 
Excellent tutorial on Struts and Tiles
Excellent tutorial on Struts and Tiles This tutorial assumes knowledge of Java, JDBC, Servlets, J2EE (with regards to Web applications) and JSP Struts in a holistic manner, minus the beads and crystals. The Tiles framework makes creating reusable pages
 
Good, but obsolete
Good, but obsolete
 
Java validation with dynamic proxies
Decouple validation processes from your business object implementations.
 
The JDBC RowSet Implementations Tutorial
In "The JDBC RowSet Implementations Tutorial," you will look at how to use the standard JDBC RowSet implementations specified in JSR-114.
 
Java Servlets: Design Issues
This article covers the principal concepts associated with servlets. This article examines some of the design issues, and offers some guidelines on the applicability of Java servlets for web based application development.
 
Servlet Essentials
This document explains the concepts of Java Servlets and provides a step-by-step tutorial for writing HTTP Servlets with complete source code for the example Servlets. The tutorial and the other chapters cover all facets of Servlet programming from a ...
 
The JavaTM Web Services Tutorial
A beginner's guide to developing Web services and Web applications on the Java Web Services Developer Pack
 
JSP Tutorial
This Tutorial is for beginners in the Java Server Pages Technology
 
JavaServer Pages Technology - Documentation
Sun's tutorial for Java Server Pages that provide a good introduction to design web pages with JSP.
 
Generating an XML Document with JAXB
In this tutorial, JAXB is used to generate Java classes from an XML Schema. An example XML document shall be created from the Java classes.
 
Understanding Network Class Loaders Class loaders
One of the cornerstones of Java dynamics, determine when and how classes can be added to a running Java environment.
 
Introduction To Enterprise Java Bean(EJB). WebLogic 6.0 Tutorial.
Introduction To Enterprise Java Bean(EJB). WebLogic 6.0 Tutorial. Welcome to EJB Section (Learn to Develop World Class Applications with Enterprise Java Beans) (Online WebLogic 6.0 Tutorial) Introduction To Enterprise Java Bean(EJB) Enterprise
 
Building Search Engine Applications Using Servlets !
Building Search Engine Applications Using Servlets ! Building Search Engine Applications Using Servlets Please visit http://www.webappcabaret.com/javadevelopers/search to see running copy of our search engine. Introduction This tutorial takes
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.