I was looking for an efficient date time processing in java, as I believe that there is a bit of a hitch in java's date time design (the Calendar class..) as it lacks some of the simple and basic methods for the date processing which is developer friendly.
Thanks to the project Joda Time (led by Stephen Colebourne) which is a developer friendly alternative to the JAVA's date and time API.
Here is a very basic example using the Joda time and the Calendar API.
To calculate the current year using the Calendar API :
Calendar today = Calendar.getInstance();
int year = today.get( Calendar.YEAR );
But in Joda time :
DateTime today = new DateTime();
int year = today.getYear();
For more refer Joda.org ......
Wednesday, December 16, 2009
Thursday, December 10, 2009
Exception handling
An intelligent and effective coding includes "Exception handling". Java includes three types of exceptions checked exceptions, un-checked exceptions & error.
Checked exceptions : Exceptions which are sub class of the java.lang.Exception (eg: IOExceptions)
Un-checked exceptions : Exceptions which are sub class of the java.lang.RuntimeException (eg: NullPointerException)
Error : Exceptions which are sub class of the java.lang.Error (eg: AssertionError)
In an application only three styles of exception handling can be implemented
Checked exceptions : Exceptions which are sub class of the java.lang.Exception (eg: IOExceptions)
Un-checked exceptions : Exceptions which are sub class of the java.lang.RuntimeException (eg: NullPointerException)
Error : Exceptions which are sub class of the java.lang.Error (eg: AssertionError)
In an application only three styles of exception handling can be implemented
- Do not handle any exceptions.
- Handle the exceptions in a haphazard way.
- Handle the exception in an intelligent way.
Subscribe to:
Posts (Atom)