Java is not a language with training wheels. It is a language for professional programmers.

— Hebert Sheildt

Using Bean Validations JSR-303 in a Standalone Application

JSR (Java Specification Request) are the request by any Java developer (like you and me) to the Java creators to modify or add something to the Java language.

If we want any change to the Java language, we need to submit a JSR, which is further reviewed to check its feasibility and the final decision is made by the Executive Committee for SE/EE (which includes representatives from companies like Apache, Google, IBM, Oracle, etc).

JSR 303 is for bean validation; using annotation or XML we can configure what validations are required for the bean fields.

It reduces the pain of writing code to validate the fields, JSR 303 validates the bean class for us and also allows us to display customized error messages.

I am creating a very basic example; the JSR 303 is far more capable.

This can be easily used while using Struts, Spring, etc and display the error message in the presentation layer.



MyBean.java



ValidatorTest.java



Download the following Jars and add to CLASSPATH to execute this program.

© Copyright © 2013 SourabhBawage.com. All Rights Reserved.