SDN Featured Content

Do you Think Hibernate is better technology that EJB

Java/J2EE blogs

Welcome to my java /J2EE blogs.


Friday, July 9, 2010

Example extending an existing java.util.Date class to add custom function

I have created a simple example where one can get the last month first day of month by creating a class by extending a simple java class and then creating own function.

 

package com.date.extension;
/**
*
* @author Ajay
* This example shows how we can create the extension of the existing java API classes to
* create our own custom class.
* These days all the new tools those are build using the java API are using these concepts
*
*/
public class DateExtension extends java.util.Date{

    /**
     *
     */
    private static final long serialVersionUID = -6611137942020737569L;
    public DateExtension(){
    }
    @Deprecated
    public java.util.Date getPriorMonth() {
            this.setDate(1);
            this.setMonth(this.getMonth()-1);
            return this;
         }
}

No comments: