Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java: Fail Early, Fail Often

You will have the fewest development problems and the most reliable programs by using Java's features and programming methodologies that cause your program to fail when there is a problem, and to fail as soon as possible.

You will write a lot of bugs. Just accept it, but make it as easy as possible to find them.. I've known a lot of fanatically capable programmers, but only one who wrote essentially flawless code in the first draft (Ira Rubin).

Compile-time errors are the best

Ideally, you want someone else to find your errors. Compiler error checking is your friend because it finds errors you've made immediately and tells you about them. Some development systems use continuous compilation, which informs you about problems as you type with jagged red lines appearing under your errors.

The quality of compile-time error diagnosis is a function of both language and compiler design. The basic Sun javac compiler that many development systems use gives relatively poor error diagnostics. On the other hand, the language design has many helpful features, and more are being added. Java's strong typing (variable types must be declared), required casting are good features, asserts, and exceptions all help produce correct code. Java 5 has further further improved reliability with generics (templates), type-safe enums, and a "foreach" statement. The goal of not allowing illegal programs to compile is impossible, but its interesting to think of how the language design could be improved to help prevent or detect errors at compile time.

Catch runtime errors early if possible

The worst kind of runtime error causes the program to slowly fall apart. Perhaps the greatest leap that Java made over C++ is providing runtime checks for common errors such as array indexes out of bounds and storage management, especially automatic garbage collection.

Yet, there are still many possible run-time errors. Java provides another great tool in the assert statement which checks that things that must be true really are (See Assertions). Learn about assertions and use them.

Rigorous testing

While it is true that testing can only show the presence of bugs, not their absence, it essential. Methodologies such as Extreme Programming require that test data be written before the code. The JUnit testing facility makes writing and running tests much easier. With fast machines it is possible to run regression tests frequently.

Fail early, fail often

You will write bugs and you want them caught as early as possible. Use types to help catch errors at compile time if possible; use assertions to stop execution if something is wrong; use rigorous testing to find errors.


Ask programming questions?



Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

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

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]