Join Now ! / Login
 
 
 
Java Geeks
Knowledge sharing Circle ---> Won't have End!!!
 
Struts - Data Source
In this brief note on Struts-DataSource, we will see how to use the declarative-management of local DataSource in Struts. The Action class does not do any business logic but simply passes on the query to the helper class and invokes the method of the helper class. This way, we are able to decouple the business logic from the struts action class. This is conducive to easy change-management, if required. In the simplest case, the helper bean itself may carry out the database operation and return the result to the action class. Or it may call a stateless-sesion ejb , which carries out the db operation. In a more advanced scenario, the session ejb may simply act as a facade for CMP or Hibernate. This is the recommended practice.
 
 Strictly speaking, Struts does not deal with the business logic. It is more concerned with presentation and overall control of flow.
 
However, in some very simple cases, we can deviate from this norm and make use of the action class itself to carry out the db operation. It is for this purpose that there is provision for Data-Sources tags in the Struts-config.xml    file. Normally this would have been commented out. James Goodwill in his book ‘Mastering Jakarta Struts ‘ has made use of this method. It leaves out a very important step and leads to problems, if we strictly follow the book. The lesson tries to clarify this point.
 
    If we are using this method, it will not be possible to use any helper class. The action class itself will carry out the db operation. The action class is actually based on Servlet API. Thus, we can skip the helper bean and even the result bean and use just two java-classes ( dbform & dbAction ) and two JSP files ( dbSubmit & dbOutput ).
   As usual we begin by going to our project directory, which in our case is
g:\examplestruts.
   The package name is dbpack and so we create a subfolder under examplestruts , named ‘dbpack‘. We create the following 4 files there.
   1) dbSubmit.jsp
   2) dbForm.java
   3) dbAction.java
   4) dbOutput.jsp
  The four files have been given below.As the focus now is simply on the correct usage of DataSource tags, we will do away with any validation code and keep our example simple to follow.
—————————————-
 
//..\dbpack\dbSubmit.jsp
 
<%@ taglib     prefix=”html”
  uri=”/WEB-INF/struts-html.tld   %>
 
<%@ taglib     prefix=”bean”
  uri=”/WEB-INF/struts-bean.tld    %>
 
<%@ taglib    prefix=”logic”
  uri=”/WEB-INF/struts-logic.tld   %>
 
 
 
< html:html>
<body bgcolor=pink>       
 
 
<html:form       action=”/db”
                name=”dbForm
                type=”dbpack.dbForm “>
 
     <html:text     property=”name”/>  <br >
     <html:text     property=”query”/> <br>
     <html:submit />
</html:form >
</body>
</html:html >
===========================================
 
 
//..\dbpack\dbForm.java
 
package       dbpack;
 
import javax.servlet.http.*;
import org.apache.struts.action.*;
 
public class dbForm extends ActionForm
{
 
     String   name=null;
     String   query=null;
 
    //—————————-
 
  public String getName ()
  {        return    name;  }             
 
 
  public void setName(String  s)
  {        name=s;  }
 
   //——————————-
  public String getQuery()
  {        return    query;  }            
 
 
  public void setQuery(String  s)
  {        query=s;  }
 
 
  public void reset
     (ActionMapping mapping,
       HttpServletRequest request)
  {
      name= null;
      query=null;
  }
 
 
  public  ActionErrors    validate
               (ActionMapping               mapping, 
                HttpServletRequest      request)
       {
  ActionErrors    errors  = new ActionErrors();
 
       if( name.length ()==0)
       {
errors.add ( “name”,
  new ActionError(”errors.nullname“));
       }     
 
       return    errors;
 
       }    
 
}
========================================
 
//..\dbpack\dbAction.java
 
package  dbpack ;
 
import  javax.sql .*;
 
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet .*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
 
public class dbAction extends Action
{
public ActionForward    execute
             (ActionMapping        mapping,
              ActionForm           form,    
              HttpServletRequest   request,
              HttpServletResponse response)
              throws IOException,ServletException
  {
                                       
  dbForm   dbform =     (dbForm)     form;
 
  String       a = dbform.getName ();
  String       b = dbform.getQuery ();
 
  if( a.equals (”ADMIN”))
  {
     String   r = “ok”;
   try
   {
    ServletContext context= servlet.getServletContext ();
 
    DataSource datasource=
(DataSource )context.getAttribute
              (Action.DATA_SOURCE_KEY);
 
Connectioncon= datasource.getConnection ();
 
  Statement st = con.createStatement ( );
    ResultSet rs= st.executeQuery (b);
 
    while( rs.next())
    {
r=r+rs.getString (1)+”…”+rs.getString(2);
    }
   }
   catch(Exception e1)
   {    r=” “+e1;  }
 
    
  HttpSession      session = request.getSession ( );
     session.setAttribute (result”,r);
 
return( mapping.findForward (”success”));
  }
 
 
  else
    {   
  return( mapping.findForward(”failure”));    
    }
    
 }
 
}
=========================================
 
 
//..\dbpack\dbOutput.jsp
 
 
<html>
<body bgcolor=lightgreen>
 
     <%
 String   r  =
(String) session.getAttribute (“result”);
     out.println (r);
     %>
 
</body>
</html>
========================================
After creating the above four files, we set the path and classpath as follows:
set path=c:\windows\command;d:\jdk1.4.2\bin
—————–
set classpath =g:\examplestruts;
c:\quick\struts.jar;
d:\tomcat41\common\lib\servlet.jar
 
( to be typed in a single line . We have placed struts.jar from the lib folder of struts distribution in C:drive for easily remembering the classpath).
==========================================
   compile    dbForm and  dbAction. Copy the two class files to  :
  d:\tomcat41\webapps\dbapp\WEB-INF\classes\dbpack.
 
copy  dbSubmit.jsp & dbOutput.jsp   to :
d:\tomcat41\webapps\dbapp
 
   Now we have to make the following entries in d:\tommcat41\webapps\dbapp\
WEB-INF\struts-config.xml
 
 
 
<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
 
<!DOCTYPE struts-config PUBLIC
“-//Apache Software Foundation//DTD Struts Configuration 1.1//EN”
 
 
 
<!–
 
   
 
–>
 
<struts-config >
 
 
 
<!–==== Data Source Configuration –>
 
 
 
 <data-sources>
  <data-source>
 
<set-property  property=”autoCommit       value=”false”/>
 
<set-property    property=”description”    value=”Configuration”/>
 
<set-property    property=” driverClass   value=”sun.jdbc.odbc.JdbcOdbcDriver“/>
 
<set-property   property=”maxCount        value=”4″/>
 
<set-property   property=”minCount         value=”2″/>
 
<set-property   property=”password”      value=”"/>
 
<set-property   property=” url   value=”jdbc:odbc:dbdemo“/>
 
<set-property    property=”user”        value=”"/>
 
  </data-source> 
 
 </data-sources>  
 
 
<!– ======================================== Form Bean Definitions –>
 
    <form-beans>
 
    <form-bean 
  name=”dbForm   type=”dbpack.dbForm/>
 
   </form-beans>
 
<!–   Global Exception Definitions –>
 
    <global-exceptions >      
 
    </global-exceptions>
 
<!– ===== Global Forward Definitions –>
   <global-forwards>    
    </global-forwards>
<!–   Action Mapping Definitions –>
    <action-mappings >      
 
   
     <action         path=”/db”
                     input=”/dbSubmit.jsp
                     name=”dbForm
                     type=”dbpack.dbAction
                     scope=”session”
                     validate=”true”        >
 
 <forward  name=”success”
                 path=”/dbOutput.jsp   />
 
    <forward     name=”failure”  
                 path=”/dbSubmit.jsp   />
 
      </action>
    </action-mappings>
……
 
</struts-config>
 
   ( Only the relevant portions of the struts-config.xml file have been shown above. We must be very careful, not to corrupt this file, especially the opening and closing tags for each section. We must not change the order in which the definitions occur. ).
—-
    The most important step is to copy
  struts-legacy.jar    from the lib folder of the jakarta-struts distribution  into  lib folder of tomcat41\webapps\dbapp\WEB-INF\lib   folder.
 
    Another important step is   to copy
jdbc2_0-stdext.jar     from tomcat41\common\lib  into  webapps\dbapp\WEB-INF\lib.
 
    Unless the above two steps are carried out,
  our code will not work.
—————–
 
     DataSource is a connection-pool. We use the
Struts  datasource just for testing. For  production environment, we can use the Tomcat’s connection pool.
    Now, we cd to d:\tomcat41\bin
set JAVA_HOME=D:\JDK1.4.2
>startup
    In the browser, we type the URL as:
http ://localhost:8080/dbapp/dbSubmit.jsp
( we should be careful about ‘case’. Tomcat is very much case-sensitive!).
   
     We can now enter the user-name as ‘ADMIN’ and type the query in text2. and submit.
     We get correct result.

 
 
Upload CSV

Upload CSV file to Application

 Uploading CSV file into the Web application is the one the features in most of the work flow projects. Here we can get the source code and explanation for uploading the CSV file.

 Features:

There are lots of main feature are included in this Component. These are:

1.      This Component will be giving the uploaded CSV file data in List.

2.      It allows to enter the comma within “” ex: “test, test”

3.      Getting the Uploaded data is very simple.

4.      It will be returning the error flag if any errors like file path is empty, file format is wrong .

Steps and Procedures:

1.      Copy the source code and create the Class called UploadCsv.java

2.      Create object for it by using Constructor:

3.      Calling the method called getFileDataInList()

Constructor

public UploadCsv(FormFile formfile,HttpServletRequest request, String strFilePath)

Parameter:

              FormFile – it’s an interface which is in org.apache.struts.FormFile

              HttpServletRequest - it’s an interface which is in javax.servlet.*

              String passing the file path of the uploaded file which is taken from jsp.

Calling Method

              UploadCsv ulCsv = new (formfile, request, strFilePath);

              List lstCSVFileDate = ulCsv. getFileDataInList();

Limitation:

1.      This Component will be good only for developing the application in Struts

 

Below is the Source code of Uploading CSV file. It will return you as Colection object. You please feel free to use my code if any issue or sugesstion, Please write you comments in my comment box.

Source Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.FileUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.upload.FormFile;

/**
 * @author Vijay Arasan.T,
 * @Company IVTL infoview Technologies Pvt Ltd, Chennai
 *
 */
public class UploadCsv {

    private String strTempFilePath = STRING_EMPTY;

    // Temp file to store the file data
    private File flTempFile = null;

    // byte array to store the file data
    private byte[] btFileData;

    // return true if error contains
    private boolean isErrors = false;

    // return true if Sucess Messages contains
    private boolean isMessages = false;

    // ActionErrors has error message if any
    private ActionMessages amMsg = new ActionMessages();

    // ActionErrors has error message if any
    private ActionErrors aeError = new ActionErrors();;

    // This list Contains the uploaded file data
    private List



 
 
Date Validation

Date Validation is the one the common task for all the web development. But, We are writing the code for every project Here i just share you my code which have standard date utilities. so Java Geeks just stop writing again and again date Validation and Date manipulation methods. Just use this below Class

Features

l          -Dates can be Validation Performed:

l          -Getting current date and Time using methods.

l          -Validation of typed in dates - eg 2001/02/29 won’t be accepted. Knows leap years.

l          -Allowed input formats are: American mm/dd/yyyy (12/31/2003), European dd.mm.yyyy (31.12.2003), ISO -yyyy-mm-dd (2003-12-31) and Japan yyyy/mm/dd (2009/03/03).

l          -Display format can be one of American, European  etc.,.

 

Functions in DateUtils.

getCurrentDate():

Returns Date. Pattern for date:  yyyyMMdd.

getCurrentDateFormat():

Returns Date. Pattern for date:  yyyy/MM/dd

getPreviousDate ():

Returns Previous Date. Pattern for date:  yyyyMMdd.

getCurrentDateDD()

  Returns Current Date. Pattern for date:  dd.

 getCurrentDay()

 Returns Current Day

 getCurrentDateYM()

   Returns Current Year&Month. Pattern for date:  yyyyMM.

getCurrentMonth()

Returns Current Month. Pattern for date:  MM.

getCurrentYear()

Returns Current Year. Pattern for date:  yyyy.

 getCurrentTime()

Returns Current Time. Pattern for Time:  HHmmssSSS.

 getCurrentTimeHMS()

Returns Current Time. Pattern for Time:  HHmmss.

getCurrentTimeHM()

Returns Current Time. Pattern for Time:  HHmm.

getCurrentTimeStamp()

Returns Current Timestamp.

getYMD(String date, String pattern)

Returns Date in YYYYMMDD Format.

 getYM(String date, String pattern)

Returns Year&Month in YYYYMM Format.

 SimpleDateFormat getDateFormat(String pattern)

Returns YYYYMMDD Format.

 isDateYear(String yyyymmdd)

Validates Date and returns Date               

isYM(String yyyymm)

Validates Year&Month and returns Year&Month                       

isTimeHM(String strTime)

Validates Time and returns Time

isDateYYYYMMDD(String strDate)

Validates Date and returns Boolean                          

isDateYYYYMM(String strDate)

Validates Year&Month and returns Boolean                          

isTimeHHMM(String strTime)

Validates Time and returns Boolean

setDate(String strValue) 

 Validates Date and returns yyyyMMDD format

getDate(String strValue)

Validates Date and returns yyyy/MM/DD format                     

setYM(String strValue)

Validates Year&Month and returns yyyyMM format                         

getYM(String strValue)

Validates Year&Month and returns yyyy/MM format

setTime(String strValue)

Validates Time and returns HHMM format                 

getTime(String strValue)

Validates Time and returns HH:MM format

isNumber(String strInput)

Check given String is Number

isDecimal(String strInput)

Check given String is Decimal

isValidDate(String strDate)

Validates Date and returns Boolean                          

isValidYM(String strDate)

Validates Year&Month and returns Boolean           

isValidTimeHM(String strTime)

 Validates Time and returns Boolean

CompareDate(String strFromDate, String strToDate)

 Compares two date and returns Boolean

 

How Can Use Methods?

DateUtils class all methods are written as static method. Call method following way

DateUtils.MethodName();

For example,

DateUtils.getCurrentDate();

DateUtils.isNumber(StrValue);

DateUtils.isValidaYYYYMMDD(strDate);

Use this Program for your Date Manipulations.

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public abstract class DateUtils{

    public static final long TIME_IN_MILLI_SECONDS = 24 * 60 * 60 * 1000 ;
    public static final int INT_ZERO = 0;
    public static final int INT_ONE = 1;
    public static final int INT_TWO = 2;
    public static final int INT_THREE = 3;
    public static final int INT_FOUR = 4;
    public static final int INT_FIVE = 5;
    public static final int INT_SIX = 6;
    public static final int INT_SEVEN = 7;
    public static final int INT_EIGHT = 8;
    public static final int INT_NINE = 3;
    public static final int INT_TEN = 10;
    public static final int INT_13 = 13;
    public static final int INT_9999 = 9999;
    public static final int INT_14 = 14;
    public static final int INT_23 = 23;
    public static final int INT_59 = 59;
    public static final String STRING_DATE_FORMAT_YYYYMMDD = “yyyyMMdd”;
    public static final String STRING_DATE_FORMAT = “yyyy/MM/dd”;
    public static final String STRING_EMPTY = “”;
    public static final String STRING_SPACE = ” “;
    public static final String STRING_ZERO = “0″;
    public static final String STRING_SLASH = “/”;
    public static final String STRING_HYPEN= “-”;
    public static final String STRING_DOT = “.”;
    public static final char CHAR_SLASH = ‘/’;
    public static final char CHAR_COLON = ‘:’;
    public static final String STRING_COLON = “:”;
    public static final String FIRST_DAY = “01″ ;

/**
     * Getting Current Date
     * @return yyyyMMdd Format Date
     */
    public static String getCurrentDate(){
        return getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(new Date());
    }
   
    /**
     * Getting Previous Day Date
     * @return yyyyMMdd Format Date
     */
    public static String getPreviousDate(){
        return getDate(getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(new Date().getTime()-TIME_IN_MILLI_SECONDS));
    }
   
    /**
     * Getting Current Day
     * @return dd Format Day
     */   
    public static String getCurrentDateDD()
    {
        return getDateFormat(”dd”).format(new Date());
    }
   
    /**
     * Getting Current Day Name
     * @return Day Name
     */   
    public static String getCurrentDay()
    {
        return getDateFormat(”EEEE”).format(new Date());
    }
   
    /**
     * Getting Current Date
     * @return yyyy/MM/dd Format Date
     */   
    public static String getCurrentDateFormat()
    {
        return getDateFormat(STRING_DATE_FORMAT).format(new Date());
    }
   
    /**
     * Getting Current Year and Month
     * @return yyyy/MM Format Date
     */      
    public static String getCurrentDateYM()
    {
        return getDateFormat(”yyyy/MM”).format(new Date());
    }
   
    /**
     * Getting Current Month
     * @return MM
     */    
    public static String getCurrentMonth()
    {
        return getDateFormat(”MM”).format(new Date());
    }
   
    /**
     * Getting Current Year
     * @return yyyy
     */    
    public static String getCurrentYear()
    {
        return getDateFormat(”yyyy”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmmssSSS Format Time
     */    
    public static String getCurrentTime()
    {
        return getDateFormat(”HHmmssSSS”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmmss Format Time
     */        
    public static String getCurrentTimeHMS()
    {
        return getDateFormat(”HHmmss”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmm Format Time
     */         
    public static String getCurrentTimeHM()
    {
        return getDateFormat(”HHmm”).format(new Date());
    }
   
    /**
     * Getting Current Time Stamp
     * @return Time Stamp
     */     
    public static String getCurrentTimeStamp()
    {
        return (new Timestamp(System.currentTimeMillis())).toString();
    }

  
   
    /**
     * Get Date in YYYYMMDD Format
     * @param date
     * @param pattern
     * @return Date
     */
    public static String getYMD(String date, String pattern)
    {
        try
        {
            Date d = getDateFormat(pattern).parse(date);
            return getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(d);
        }
        catch(ParseException e)
        {
            return date;
        }
    }

    /**
     * Get Year and Month in YYYYMM Format
     * @param date
     * @param pattern
     * @return YM
     */   
    public static String getYM(String date, String pattern)
    {
        try
        {
            Date d = getDateFormat(pattern).parse(date);
            return getDateFormat(”yyyyMM”).format(d);
        }
        catch(ParseException e)
        {
            return date;
        }
    }
   
    /**
     * Setting Pattern For Date
     * @param pattern
     * @return Date Format
     */
    private static SimpleDateFormat getDateFormat(String pattern)
    {
        SimpleDateFormat sf = new SimpleDateFormat(pattern);
       
        sf.setLenient(false);
        return sf;
    }

   
      
    /**
     * To get the date from user and
     * remove the special char 
     * @param  String yyyymmdd
     * @return String yyyymmdd
     */
    public static String isDateYear(String yyyymmdd) {
       
       
            if(yyyymmdd.contains(STRING_SLASH)){
               
                String[] splitDate = yyyymmdd.split(STRING_SLASH);
               
                String strYear = splitDate[INT_ZERO];
                String strMonth = splitDate[INT_ONE];
                String strDate = splitDate[INT_TWO];
               
                if(strMonth.length() == 1){
                    strMonth = STRING_ZERO + strMonth;
                }
               
                if(strDate.length() == 1){
                    strDate = STRING_ZERO + strDate;
                }       
               
                yyyymmdd = strYear + STRING_SLASH + strMonth + STRING_SLASH + strDate;               
               
            }

            // To change correct format
            yyyymmdd = yyyymmdd.replace(STRING_SLASH, STRING_EMPTY);
            yyyymmdd = yyyymmdd.replace(STRING_HYPEN, STRING_EMPTY);
            yyyymmdd = yyyymmdd.replace(STRING_DOT, STRING_EMPTY);
            return yyyymmdd;           
    }     
   
    /**
     * To get the date from user and
     * remove the special char 
     * @param  String yyyymm
     * @return String yyyymm
     */
    public static String isYM(String yyyymm) {
       
       
        if(yyyymm.contains(STRING_SLASH)){
           
            String[] splitDate = yyyymm.split(STRING_SLASH);
           
            String strYear = splitDate[INT_ZERO];
            String strMonth = splitDate[INT_ONE];
           
            if(strMonth.length() == 1){
                strMonth = STRING_ZERO + strMonth;
            }
       
            yyyymm = strYear + STRING_SLASH + strMonth;               
           
        }   

            // To change correct format
            yyyymm = yyyymm.replace(STRING_SLASH, STRING_EMPTY);
            yyyymm = yyyymm.replace(STRING_HYPEN, STRING_EMPTY);
            yyyymm = yyyymm.replace(STRING_DOT, STRING_EMPTY);
            return yyyymm;           
    }   
   
    /**
     * To get the time from user and
     * remove the special char 
     * @param  String strTime
     * @return String strTime
     */
    public static String isTimeHM(String strTime) {

            // To change correct format
            strTime = strTime.replace(STRING_SLASH, STRING_EMPTY);
            strTime = strTime.replace(STRING_HYPEN, STRING_EMPTY);
            strTime = strTime.replace(STRING_DOT, STRING_EMPTY);
            strTime = strTime.replace(STRING_COLON, STRING_EMPTY);
            return strTime;           
    }   

    /**
     * To get the date from the user and
     * check the date is valid or not
     * @param date String
     * @return boolean returnBoolean
     */
    public static boolean isDateYYYYMMDD(String strDate) {
       
        boolean returnBoolean = true;
        if(strDate.length() > 10){
            returnBoolean = false;   
        }else if(strDate.length() < 8) {
            returnBoolean = false;   
        }else if(!strDate.contains(STRING_SLASH)){
            returnBoolean = false;               
        }else if(strDate.contains(STRING_SLASH)){
            String strTempDate = strDate.replaceAll(STRING_SLASH, STRING_EMPTY);       
           
            if(!isNumber(strTempDate)){               
                returnBoolean = false;
            }else if(!isValidDate(strDate)){
                returnBoolean = false;           
            }
        }else{
            if(strDate.length() == INT_EIGHT){
                String strTempDate = strDate.substring(INT_ZERO, INT_FOUR) + STRING_SLASH + strDate.substring(INT_FOUR, INT_SIX) 
                                                    + STRING_SLASH + strDate.substring(INT_SIX, INT_EIGHT);

                if(strDate.contains(STRING_SLASH)) {               
                    returnBoolean = false;
                }else if(!isNumber(strDate)){               
                    returnBoolean = false;
                }else if(!isValidDate(strTempDate)){
                    returnBoolean = false;               
                }
            }else{
                returnBoolean = false;   
            }
        }
       
        return returnBoolean;
    }
   
    /**
     * To get the date from the user and
     * check the date is valid or not
     * @param date String
     * @return boolean returnBoolean
     */
    public static boolean isDateYYYYMM(String strDate) {
       
        boolean returnBoolean = true;
       
        if(strDate.contains(STRING_SLASH)){
            String strTempDate = strDate.replaceAll(STRING_SLASH, STRING_EMPTY);       
           
            if(!isNumber(strTempDate)){               
                returnBoolean = false;
            }else if(!isValidYM(strDate)){
                returnBoolean = false;           
            }
        }else{
            if(strDate.length() == INT_SIX) {       
           
                String strTempDate = strDate.substring(INT_ZERO, INT_FOUR) + STRING_SLASH + strDate.substring(INT_FOUR, INT_SIX);
               
                if(strDate.contains(STRING_SLASH)) {               
                    returnBoolean = false;
                }else if(!isNumber(strDate)){               
                    returnBoolean = false;
                }else if(!isValidYM(strTempDate)){
                    returnBoolean = false;               
                }
            }else{
                returnBoolean = false;
            }
        }
       
        return returnBoolean;
    }
   

   
    /**
     * To get the Time from the user and
     * check the Time is valid or not
     * @param Time String
     * @return boolean returnBoolean
     */
    public static boolean isTimeHHMM(String strTime) {
       
        boolean returnBoolean = true;
       
        if (strTime.length() == INT_FIVE) {   
            String strTempTime = strTime.substring(INT_ZERO, INT_TWO) + strTime.substring(INT_THREE, INT_FOUR);
           
            if(!(strTime.charAt(INT_TWO) == CHAR_COLON)) {               
                returnBoolean = false;
            } else if(!isNumber(strTempTime)){               
                returnBoolean = false;
            }else if(!isValidTimeHM(strTime)){
                returnBoolean = false;           
            }
        } else if(strTime.length() == INT_FOUR) {       
           
            String strTempTime = strTime.substring(INT_ZERO, INT_TWO) + STRING_COLON + strTime.substring(INT_TWO, INT_FOUR);
           
            if(strTime.contains(STRING_COLON)) {               
                returnBoolean = false;
            }else if(!isNumber(strTime)){               
                returnBoolean = false;
            }else if(!isValidTimeHM(strTempTime)){
                returnBoolean = false;               
            }
        }else{
            returnBoolean = false;
        }
       
        return returnBoolean;
    }
       

   
    /**
     * Removing Date Seperator From Date
     * @param strValue
     * @return date in YYYYMMDD Format
     */
    public static String setDate(String strValue)  {
       
        if(isDateYYYYMMDD(strValue)){
            strValue = isDateYear(strValue);       
        }
        return strValue;
    }

    /**
     * Adding Date Seperator To Date
     * @param strValue
     * @return date in YYYY/MM/DD Format
     */
    public static String getDate(String strValue){
       
        if(strValue != null && strValue.length()== INT_EIGHT){
            strValue = strValue.substring(INT_ZERO, INT_FOUR)    + STRING_SLASH +strValue.substring(INT_FOUR, INT_SIX)
                                + STRING_SLASH +strValue.substring(INT_SIX, INT_EIGHT);   
        }
    return strValue;
    }
   
    /**
     * Removing Seperator From Year&Month
     * @param strValue
     * @return Year&Month in YYYYMM Format
     */   
    public static String setYM(String strValue)  {
       
        if(isDateYYYYMM(strValue)){
            strValue = isYM(strValue);       
        }
       
        return strValue;
    }

    /**
     * Adding Seperator From Year&Month
     * @param strValue
     * @return Year&Month in YYYY/MM Format
     */       
    public static String getYM(String strValue){
       
        if(strValue != null && strValue.length()== INT_SIX){
            strValue = strValue.substring(INT_ZERO, INT_FOUR)    + STRING_SLASH +strValue.substring(INT_FOUR, INT_SIX);   
        }
    return strValue;
    }   
   
    /**
     * Removing Seperator From Time
     * @param strValue
     * @return Time in HHMM Format
     */       
    public static String setTime(String strValue)  {
       
        if(isTimeHHMM(strValue)){
            strValue = isTimeHM(strValue);       
        }
        return strValue;
    }
   
    /**
     * Adding Seperator From Time
     * @param strValue
     * @return Time in HH:MM Format
     */           
    public static String getTime(String strValue){
       
        if(strValue != null && strValue.length()== INT_FOUR){
            strValue = strValue.substring(INT_ZERO, INT_TWO) + STRING_COLON + strValue.substring(INT_TWO, INT_FOUR);   
        }else if(strValue != null && strValue.length()> INT_FOUR){
            strValue = strValue.substring(INT_ZERO, INT_TWO) + STRING_COLON + strValue.substring(INT_TWO, INT_FOUR);
        }
    return strValue;
    }   
   
    /**
     * Check Input is Number or not
     * @param strInput
     * @return true/false
     */
    public static boolean isNumber(String strInput){
        if(strInput==null ||strInput.equals(STRING_EMPTY)){
            return false;
        }
        else{
          for(int intIndex = INT_ZERO; intIndex < strInput.length(); intIndex++){
              if ( !Character.isDigit(strInput.charAt(intIndex))){
                 return false;
              }
         }
         return true;
        }
       
    }
   
    /**
     * Check Input is Decimal or not
     * @param strInput
     * @return true/false
     */   
    public static boolean isDecimal(String strInput){
        boolean booReturn = false;
        if(strInput.contains(”.”)
                && (strInput.indexOf(”.”) == strInput.lastIndexOf(”.”))
                && (isNumber(strInput.replace(”.”, “”)))){
           
            booReturn = true;
           
        } else if(!strInput.contains(”.”)
                && (isNumber(strInput))){
            booReturn = true;
        }
        return booReturn;
       
    }
    /**
     * Check given String is date or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidDate(String strDate) {
       
       
        try{
            Date date = new Date(strDate);
               
            String[] splitDate = strDate.split(STRING_SLASH);
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
           
            String strYear = splitDate[INT_ZERO];
            String strMonth = splitDate[INT_ONE];       
            String strDay = splitDate[INT_TWO];           
           
            if(strYear == null || strYear.equals(STRING_EMPTY)){
                return false;
            }else if(strYear.length() != 4){
                return false;
            }else if(strMonth == null || strMonth.equals(STRING_EMPTY)){
                return false;
            }else if(strMonth.length() != 1 && strMonth.length() != 2){
                return false;       
            }else if(strDay == null || strDay.equals(STRING_EMPTY)){
                return false;
            }else if(strDay.length() != 1 && strDay.length() != 2){
                return false;                   
            }
           
            int intYear = Integer.parseInt(splitDate[INT_ZERO]);
            int intMonth = Integer.parseInt(splitDate[INT_ONE]) - INT_ONE;       
            int intDate = Integer.parseInt(splitDate[INT_TWO]);
           
            if(calendar.get(Calendar.DATE) != intDate){
                return false;
            } else if(calendar.get(Calendar.MONTH) != intMonth){
                return false;
            }else if(intYear > INT_9999 || intYear < 1000){
                return false;
            } else if(calendar.get(Calendar.YEAR) != intYear){
                return false;
            }
        }catch (Exception e) {
            return false;
        }
        return true;
    }
   

   
    /**
     * Check given String is Year&Month or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidYM(String strDate) {
       
       
        String[] splitDate = strDate.split(STRING_SLASH);
        if(splitDate != null && splitDate.length == 2){
            try{
                int intYear = Integer.parseInt(splitDate[INT_ZERO]);
                int intMonth = Integer.parseInt(splitDate[INT_ONE]);   
                       
                if(intMonth < INT_13 && intMonth > INT_ZERO && intYear < INT_9999 && intYear > INT_ZERO){
                    return true;
                } else {
                      return false;
                }
            }catch (Exception e) {
                return false;
            }
        }else{
            return false;
        }

    }   
   
    /**
     * Check given String is Time or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidTimeHM(String strTime) {
       
        String[] splitDate = strTime.split(STRING_COLON);
        if(splitDate != null && splitDate.length == 2){
            try{
                int intHour = Integer.parseInt(splitDate[INT_ZERO]);
                int intMinute = Integer.parseInt(splitDate[INT_ONE]);       
                if(intHour < INT_ZERO){
                    return false;
                } else if(intHour > INT_23){
                    return false;
                } else if(intMinute < INT_ZERO){
                    return false;
                } else if(intMinute > INT_59){
                    return false;           
                }
            }catch (Exception e) {
                return false;
            }               
        }else{
            return false;
        }       
        return true;
    }   
   

   
    /**
     * Checks Two Date (End Date Greater Than From Date)
     * @param strFromDate
     * @param strToDate
     * @return true/false
     * @throws ParseException
     */
    public static boolean CompareDate(String strFromDate, String strToDate) throws ParseException {
        boolean booFlag = true;
        if(isDateYYYYMMDD(strFromDate) && isDateYYYYMMDD(strToDate)) {
            if(!strFromDate.equals(strToDate)) {
                Date FromDate = getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).parse(setDate(strFromDate));
                Date ToDate = getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).parse(setDate(strToDate));
                booFlag = FromDate.before(ToDate);
            }
        }
        return booFlag;
    }

}

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public abstract class DateUtils{

    public static final long TIME_IN_MILLI_SECONDS = 24 * 60 * 60 * 1000 ;
   
    public static final int INT_ZERO = 0;
   
    public static final int INT_ONE = 1;
   
    public static final int INT_TWO = 2;
   
    public static final int INT_THREE = 3;
   
    public static final int INT_FOUR = 4;
   
    public static final int INT_FIVE = 5;
   
    public static final int INT_SIX = 6;
   
    public static final int INT_SEVEN = 7;
   
    public static final int INT_EIGHT = 8;
   
    public static final int INT_NINE = 3;
   
    public static final int INT_TEN = 10;
   
    public static final int INT_13 = 13;
   
    public static final int INT_9999 = 9999;
   
    public static final int INT_14 = 14;
   
    public static final int INT_23 = 23;
   
    public static final int INT_59 = 59;
   
    public static final String STRING_DATE_FORMAT_YYYYMMDD = “yyyyMMdd”;
   
    public static final String STRING_DATE_FORMAT = “yyyy/MM/dd”;
   
    public static final String STRING_EMPTY = “”;
   
    public static final String STRING_SPACE = ” “;
   
    public static final String STRING_ZERO = “0″;
   
    public static final String STRING_SLASH = “/”;
   
    public static final String STRING_HYPEN= “-”;
   
    public static final String STRING_DOT = “.”;
   
    public static final char CHAR_SLASH = ‘/’;
   
    public static final char CHAR_COLON = ‘:’;
   
    public static final String STRING_COLON = “:”;
       
    public static final String FIRST_DAY = “01″ ;
   
    /**
     * Getting Current Date
     * @return yyyyMMdd Format Date
     */
    public static String getCurrentDate(){
        return getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(new Date());
    }
   
    /**
     * Getting Previous Day Date
     * @return yyyyMMdd Format Date
     */
    public static String getPreviousDate(){
        return getDate(getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(new Date().getTime()-TIME_IN_MILLI_SECONDS));
    }
   
    /**
     * Getting Current Day
     * @return dd Format Day
     */   
    public static String getCurrentDateDD()
    {
        return getDateFormat(”dd”).format(new Date());
    }
   
    /**
     * Getting Current Day Name
     * @return Day Name
     */   
    public static String getCurrentDay()
    {
        return getDateFormat(”EEEE”).format(new Date());
    }
   
    /**
     * Getting Current Date
     * @return yyyy/MM/dd Format Date
     */   
    public static String getCurrentDateFormat()
    {
        return getDateFormat(STRING_DATE_FORMAT).format(new Date());
    }
   
    /**
     * Getting Current Year and Month
     * @return yyyy/MM Format Date
     */      
    public static String getCurrentDateYM()
    {
        return getDateFormat(”yyyy/MM”).format(new Date());
    }
   
    /**
     * Getting Current Month
     * @return MM
     */    
    public static String getCurrentMonth()
    {
        return getDateFormat(”MM”).format(new Date());
    }
   
    /**
     * Getting Current Year
     * @return yyyy
     */    
    public static String getCurrentYear()
    {
        return getDateFormat(”yyyy”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmmssSSS Format Time
     */    
    public static String getCurrentTime()
    {
        return getDateFormat(”HHmmssSSS”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmmss Format Time
     */        
    public static String getCurrentTimeHMS()
    {
        return getDateFormat(”HHmmss”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmm Format Time
     */         
    public static String getCurrentTimeHM()
    {
        return getDateFormat(”HHmm”).format(new Date());
    }
   
    /**
     * Getting Current Time Stamp
     * @return Time Stamp
     */     
    public static String getCurrentTimeStamp()
    {
        return (new Timestamp(System.currentTimeMillis())).toString();
    }

  
   
    /**
     * Get Date in YYYYMMDD Format
     * @param date
     * @param pattern
     * @return Date
     */
    public static String getYMD(String date, String pattern)
    {
        try
        {
            Date d = getDateFormat(pattern).parse(date);
            return getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(d);
        }
        catch(ParseException e)
        {
            return date;
        }
    }

    /**
     * Get Year and Month in YYYYMM Format
     * @param date
     * @param pattern
     * @return YM
     */   
    public static String getYM(String date, String pattern)
    {
        try
        {
            Date d = getDateFormat(pattern).parse(date);
            return getDateFormat(”yyyyMM”).format(d);
        }
        catch(ParseException e)
        {
            return date;
        }
    }
   
    /**
     * Setting Pattern For Date
     * @param pattern
     * @return Date Format
     */
    private static SimpleDateFormat getDateFormat(String pattern)
    {
        SimpleDateFormat sf = new SimpleDateFormat(pattern);
       
        sf.setLenient(false);
        return sf;
    }

   
      
    /**
     * To get the date from user and
     * remove the special char 
     * @param  String yyyymmdd
     * @return String yyyymmdd
     */
    public static String isDateYear(String yyyymmdd) {
       
       
            if(yyyymmdd.contains(STRING_SLASH)){
               
                String[] splitDate = yyyymmdd.split(STRING_SLASH);
               
                String strYear = splitDate[INT_ZERO];
                String strMonth = splitDate[INT_ONE];
                String strDate = splitDate[INT_TWO];
               
                if(strMonth.length() == 1){
                    strMonth = STRING_ZERO + strMonth;
                }
               
                if(strDate.length() == 1){
                    strDate = STRING_ZERO + strDate;
                }       
               
                yyyymmdd = strYear + STRING_SLASH + strMonth + STRING_SLASH + strDate;               
               
            }

            // To change correct format
            yyyymmdd = yyyymmdd.replace(STRING_SLASH, STRING_EMPTY);
            yyyymmdd = yyyymmdd.replace(STRING_HYPEN, STRING_EMPTY);
            yyyymmdd = yyyymmdd.replace(STRING_DOT, STRING_EMPTY);
            return yyyymmdd;           
    }     
   
    /**
     * To get the date from user and
     * remove the special char 
     * @param  String yyyymm
     * @return String yyyymm
     */
    public static String isYM(String yyyymm) {
       
       
        if(yyyymm.contains(STRING_SLASH)){
           
            String[] splitDate = yyyymm.split(STRING_SLASH);
           
            String strYear = splitDate[INT_ZERO];
            String strMonth = splitDate[INT_ONE];
           
            if(strMonth.length() == 1){
                strMonth = STRING_ZERO + strMonth;
            }
       
            yyyymm = strYear + STRING_SLASH + strMonth;               
           
        }   

            // To change correct format
            yyyymm = yyyymm.replace(STRING_SLASH, STRING_EMPTY);
            yyyymm = yyyymm.replace(STRING_HYPEN, STRING_EMPTY);
            yyyymm = yyyymm.replace(STRING_DOT, STRING_EMPTY);
            return yyyymm;           
    }   
   
    /**
     * To get the time from user and
     * remove the special char 
     * @param  String strTime
     * @return String strTime
     */
    public static String isTimeHM(String strTime) {

            // To change correct format
            strTime = strTime.replace(STRING_SLASH, STRING_EMPTY);
            strTime = strTime.replace(STRING_HYPEN, STRING_EMPTY);
            strTime = strTime.replace(STRING_DOT, STRING_EMPTY);
            strTime = strTime.replace(STRING_COLON, STRING_EMPTY);
            return strTime;           
    }   

    /**
     * To get the date from the user and
     * check the date is valid or not
     * @param date String
     * @return boolean returnBoolean
     */
    public static boolean isDateYYYYMMDD(String strDate) {
       
        boolean returnBoolean = true;
        if(strDate.length() > 10){
            returnBoolean = false;   
        }else if(strDate.length() < 8) {
            returnBoolean = false;   
        }else if(!strDate.contains(STRING_SLASH)){
            returnBoolean = false;               
        }else if(strDate.contains(STRING_SLASH)){
            String strTempDate = strDate.replaceAll(STRING_SLASH, STRING_EMPTY);       
           
            if(!isNumber(strTempDate)){               
                returnBoolean = false;
            }else if(!isValidDate(strDate)){
                returnBoolean = false;           
            }
        }else{
            if(strDate.length() == INT_EIGHT){
                String strTempDate = strDate.substring(INT_ZERO, INT_FOUR) + STRING_SLASH + strDate.substring(INT_FOUR, INT_SIX) 
                                                    + STRING_SLASH + strDate.substring(INT_SIX, INT_EIGHT);

                if(strDate.contains(STRING_SLASH)) {               
                    returnBoolean = false;
                }else if(!isNumber(strDate)){               
                    returnBoolean = false;
                }else if(!isValidDate(strTempDate)){
                    returnBoolean = false;               
                }
            }else{
                returnBoolean = false;   
            }
        }
       
        return returnBoolean;
    }
   
    /**
     * To get the date from the user and
     * check the date is valid or not
     * @param date String
     * @return boolean returnBoolean
     */
    public static boolean isDateYYYYMM(String strDate) {
       
        boolean returnBoolean = true;
       
        if(strDate.contains(STRING_SLASH)){
            String strTempDate = strDate.replaceAll(STRING_SLASH, STRING_EMPTY);       
           
            if(!isNumber(strTempDate)){               
                returnBoolean = false;
            }else if(!isValidYM(strDate)){
                returnBoolean = false;           
            }
        }else{
            if(strDate.length() == INT_SIX) {       
           
                String strTempDate = strDate.substring(INT_ZERO, INT_FOUR) + STRING_SLASH + strDate.substring(INT_FOUR, INT_SIX);
               
                if(strDate.contains(STRING_SLASH)) {               
                    returnBoolean = false;
                }else if(!isNumber(strDate)){               
                    returnBoolean = false;
                }else if(!isValidYM(strTempDate)){
                    returnBoolean = false;               
                }
            }else{
                returnBoolean = false;
            }
        }
       
        return returnBoolean;
    }
   

   
    /**
     * To get the Time from the user and
     * check the Time is valid or not
     * @param Time String
     * @return boolean returnBoolean
     */
    public static boolean isTimeHHMM(String strTime) {
       
        boolean returnBoolean = true;
       
        if (strTime.length() == INT_FIVE) {   
            String strTempTime = strTime.substring(INT_ZERO, INT_TWO) + strTime.substring(INT_THREE, INT_FOUR);
           
            if(!(strTime.charAt(INT_TWO) == CHAR_COLON)) {               
                returnBoolean = false;
            } else if(!isNumber(strTempTime)){               
                returnBoolean = false;
            }else if(!isValidTimeHM(strTime)){
                returnBoolean = false;           
            }
        } else if(strTime.length() == INT_FOUR) {       
           
            String strTempTime = strTime.substring(INT_ZERO, INT_TWO) + STRING_COLON + strTime.substring(INT_TWO, INT_FOUR);
           
            if(strTime.contains(STRING_COLON)) {               
                returnBoolean = false;
            }else if(!isNumber(strTime)){               
                returnBoolean = false;
            }else if(!isValidTimeHM(strTempTime)){
                returnBoolean = false;               
            }
        }else{
            returnBoolean = false;
        }
       
        return returnBoolean;
    }
       

   
    /**
     * Removing Date Seperator From Date
     * @param strValue
     * @return date in YYYYMMDD Format
     */
    public static String setDate(String strValue)  {
       
        if(isDateYYYYMMDD(strValue)){
            strValue = isDateYear(strValue);       
        }
        return strValue;
    }

    /**
     * Adding Date Seperator To Date
     * @param strValue
     * @return date in YYYY/MM/DD Format
     */
    public static String getDate(String strValue){
       
        if(strValue != null && strValue.length()== INT_EIGHT){
            strValue = strValue.substring(INT_ZERO, INT_FOUR)    + STRING_SLASH +strValue.substring(INT_FOUR, INT_SIX)
                                + STRING_SLASH +strValue.substring(INT_SIX, INT_EIGHT);   
        }
    return strValue;
    }
   
    /**
     * Removing Seperator From Year&Month
     * @param strValue
     * @return Year&Month in YYYYMM Format
     */   
    public static String setYM(String strValue)  {
       
        if(isDateYYYYMM(strValue)){
            strValue = isYM(strValue);       
        }
       
        return strValue;
    }

    /**
     * Adding Seperator From Year&Month
     * @param strValue
     * @return Year&Month in YYYY/MM Format
     */       
    public static String getYM(String strValue){
       
        if(strValue != null && strValue.length()== INT_SIX){
            strValue = strValue.substring(INT_ZERO, INT_FOUR)    + STRING_SLASH +strValue.substring(INT_FOUR, INT_SIX);   
        }
    return strValue;
    }   
   
    /**
     * Removing Seperator From Time
     * @param strValue
     * @return Time in HHMM Format
     */       
    public static String setTime(String strValue)  {
       
        if(isTimeHHMM(strValue)){
            strValue = isTimeHM(strValue);       
        }
        return strValue;
    }
   
    /**
     * Adding Seperator From Time
     * @param strValue
     * @return Time in HH:MM Format
     */           
    public static String getTime(String strValue){
       
        if(strValue != null && strValue.length()== INT_FOUR){
            strValue = strValue.substring(INT_ZERO, INT_TWO) + STRING_COLON + strValue.substring(INT_TWO, INT_FOUR);   
        }else if(strValue != null && strValue.length()> INT_FOUR){
            strValue = strValue.substring(INT_ZERO, INT_TWO) + STRING_COLON + strValue.substring(INT_TWO, INT_FOUR);
        }
    return strValue;
    }   
   
    /**
     * Check Input is Number or not
     * @param strInput
     * @return true/false
     */
    public static boolean isNumber(String strInput){
        if(strInput==null ||strInput.equals(STRING_EMPTY)){
            return false;
        }
        else{
          for(int intIndex = INT_ZERO; intIndex < strInput.length(); intIndex++){
              if ( !Character.isDigit(strInput.charAt(intIndex))){
                 return false;
              }
         }
         return true;
        }
       
    }
   
    /**
     * Check Input is Decimal or not
     * @param strInput
     * @return true/false
     */   
    public static boolean isDecimal(String strInput){
        boolean booReturn = false;
        if(strInput.contains(”.”)
                && (strInput.indexOf(”.”) == strInput.lastIndexOf(”.”))
                && (isNumber(strInput.replace(”.”, “”)))){
           
            booReturn = true;
           
        } else if(!strInput.contains(”.”)
                && (isNumber(strInput))){
            booReturn = true;
        }
        return booReturn;
       
    }
    /**
     * Check given String is date or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidDate(String strDate) {
       
       
        try{
            Date date = new Date(strDate);
               
            String[] splitDate = strDate.split(STRING_SLASH);
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
           
            String strYear = splitDate[INT_ZERO];
            String strMonth = splitDate[INT_ONE];       
            String strDay = splitDate[INT_TWO];           
           
            if(strYear == null || strYear.equals(STRING_EMPTY)){
                return false;
            }else if(strYear.length() != 4){
                return false;
            }else if(strMonth == null || strMonth.equals(STRING_EMPTY)){
                return false;
            }else if(strMonth.length() != 1 && strMonth.length() != 2){
                return false;       
            }else if(strDay == null || strDay.equals(STRING_EMPTY)){
                return false;
            }else if(strDay.length() != 1 && strDay.length() != 2){
                return false;                   
            }
           
            int intYear = Integer.parseInt(splitDate[INT_ZERO]);
            int intMonth = Integer.parseInt(splitDate[INT_ONE]) - INT_ONE;       
            int intDate = Integer.parseInt(splitDate[INT_TWO]);
           
            if(calendar.get(Calendar.DATE) != intDate){
                return false;
            } else if(calendar.get(Calendar.MONTH) != intMonth){
                return false;
            }else if(intYear > INT_9999 || intYear < 1000){
                return false;
            } else if(calendar.get(Calendar.YEAR) != intYear){
                return false;
            }
        }catch (Exception e) {
            return false;
        }
        return true;
    }
   

   
    /**
     * Check given String is Year&Month or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidYM(String strDate) {
       
       
        String[] splitDate = strDate.split(STRING_SLASH);
        if(splitDate != null && splitDate.length == 2){
            try{
                int intYear = Integer.parseInt(splitDate[INT_ZERO]);
                int intMonth = Integer.parseInt(splitDate[INT_ONE]);   
                       
                if(intMonth < INT_13 && intMonth > INT_ZERO && intYear < INT_9999 && intYear > INT_ZERO){
                    return true;
                } else {
                      return false;
                }
            }catch (Exception e) {
                return false;
            }
        }else{
            return false;
        }

    }   
   
    /**
     * Check given String is Time or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidTimeHM(String strTime) {
       
        String[] splitDate = strTime.split(STRING_COLON);
        if(splitDate != null && splitDate.length == 2){
            try{
                int intHour = Integer.parseInt(splitDate[INT_ZERO]);
                int intMinute = Integer.parseInt(splitDate[INT_ONE]);       
                if(intHour < INT_ZERO){
                    return false;
                } else if(intHour > INT_23){
                    return false;
                } else if(intMinute < INT_ZERO){
                    return false;
                } else if(intMinute > INT_59){
                    return false;           
                }
            }catch (Exception e) {
                return false;
            }               
        }else{
            return false;
        }       
        return true;
    }   
   

   
    /**
     * Checks Two Date (End Date Greater Than From Date)
     * @param strFromDate
     * @param strToDate
     * @return true/false
     * @throws ParseException
     */
    public static boolean CompareDate(String strFromDate, String strToDate) throws ParseException {
        boolean booFlag = true;
        if(isDateYYYYMMDD(strFromDate) && isDateYYYYMMDD(strToDate)) {
            if(!strFromDate.equals(strToDate)) {
                Date FromDate = getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).parse(setDate(strFromDate));
                Date ToDate = getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).parse(setDate(strToDate));
                booFlag = FromDate.before(ToDate);
            }
        }
        return booFlag;
    }

}

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public abstract class DateUtils{

    public static final long TIME_IN_MILLI_SECONDS = 24 * 60 * 60 * 1000 ;
   
    public static final int INT_ZERO = 0;
   
    public static final int INT_ONE = 1;
   
    public static final int INT_TWO = 2;
   
    public static final int INT_THREE = 3;
   
    public static final int INT_FOUR = 4;
   
    public static final int INT_FIVE = 5;
   
    public static final int INT_SIX = 6;
   
    public static final int INT_SEVEN = 7;
   
    public static final int INT_EIGHT = 8;
   
    public static final int INT_NINE = 3;
   
    public static final int INT_TEN = 10;
   
    public static final int INT_13 = 13;
   
    public static final int INT_9999 = 9999;
   
    public static final int INT_14 = 14;
   
    public static final int INT_23 = 23;
   
    public static final int INT_59 = 59;
   
    public static final String STRING_DATE_FORMAT_YYYYMMDD = “yyyyMMdd”;
   
    public static final String STRING_DATE_FORMAT = “yyyy/MM/dd”;
   
    public static final String STRING_EMPTY = “”;
   
    public static final String STRING_SPACE = ” “;
   
    public static final String STRING_ZERO = “0″;
   
    public static final String STRING_SLASH = “/”;
   
    public static final String STRING_HYPEN= “-”;
   
    public static final String STRING_DOT = “.”;
   
    public static final char CHAR_SLASH = ‘/’;
   
    public static final char CHAR_COLON = ‘:’;
   
    public static final String STRING_COLON = “:”;
       
    public static final String FIRST_DAY = “01″ ;
   
    /**
     * Getting Current Date
     * @return yyyyMMdd Format Date
     */
    public static String getCurrentDate(){
        return getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(new Date());
    }
   
    /**
     * Getting Previous Day Date
     * @return yyyyMMdd Format Date
     */
    public static String getPreviousDate(){
        return getDate(getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(new Date().getTime()-TIME_IN_MILLI_SECONDS));
    }
   
    /**
     * Getting Current Day
     * @return dd Format Day
     */   
    public static String getCurrentDateDD()
    {
        return getDateFormat(”dd”).format(new Date());
    }
   
    /**
     * Getting Current Day Name
     * @return Day Name
     */   
    public static String getCurrentDay()
    {
        return getDateFormat(”EEEE”).format(new Date());
    }
   
    /**
     * Getting Current Date
     * @return yyyy/MM/dd Format Date
     */   
    public static String getCurrentDateFormat()
    {
        return getDateFormat(STRING_DATE_FORMAT).format(new Date());
    }
   
    /**
     * Getting Current Year and Month
     * @return yyyy/MM Format Date
     */      
    public static String getCurrentDateYM()
    {
        return getDateFormat(”yyyy/MM”).format(new Date());
    }
   
    /**
     * Getting Current Month
     * @return MM
     */    
    public static String getCurrentMonth()
    {
        return getDateFormat(”MM”).format(new Date());
    }
   
    /**
     * Getting Current Year
     * @return yyyy
     */    
    public static String getCurrentYear()
    {
        return getDateFormat(”yyyy”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmmssSSS Format Time
     */    
    public static String getCurrentTime()
    {
        return getDateFormat(”HHmmssSSS”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmmss Format Time
     */        
    public static String getCurrentTimeHMS()
    {
        return getDateFormat(”HHmmss”).format(new Date());
    }

    /**
     * Getting Current Time
     * @return HHmm Format Time
     */         
    public static String getCurrentTimeHM()
    {
        return getDateFormat(”HHmm”).format(new Date());
    }
   
    /**
     * Getting Current Time Stamp
     * @return Time Stamp
     */     
    public static String getCurrentTimeStamp()
    {
        return (new Timestamp(System.currentTimeMillis())).toString();
    }

  
   
    /**
     * Get Date in YYYYMMDD Format
     * @param date
     * @param pattern
     * @return Date
     */
    public static String getYMD(String date, String pattern)
    {
        try
        {
            Date d = getDateFormat(pattern).parse(date);
            return getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).format(d);
        }
        catch(ParseException e)
        {
            return date;
        }
    }

    /**
     * Get Year and Month in YYYYMM Format
     * @param date
     * @param pattern
     * @return YM
     */   
    public static String getYM(String date, String pattern)
    {
        try
        {
            Date d = getDateFormat(pattern).parse(date);
            return getDateFormat(”yyyyMM”).format(d);
        }
        catch(ParseException e)
        {
            return date;
        }
    }
   
    /**
     * Setting Pattern For Date
     * @param pattern
     * @return Date Format
     */
    private static SimpleDateFormat getDateFormat(String pattern)
    {
        SimpleDateFormat sf = new SimpleDateFormat(pattern);
       
        sf.setLenient(false);
        return sf;
    }

   
      
    /**
     * To get the date from user and
     * remove the special char 
     * @param  String yyyymmdd
     * @return String yyyymmdd
     */
    public static String isDateYear(String yyyymmdd) {
       
       
            if(yyyymmdd.contains(STRING_SLASH)){
               
                String[] splitDate = yyyymmdd.split(STRING_SLASH);
               
                String strYear = splitDate[INT_ZERO];
                String strMonth = splitDate[INT_ONE];
                String strDate = splitDate[INT_TWO];
               
                if(strMonth.length() == 1){
                    strMonth = STRING_ZERO + strMonth;
                }
               
                if(strDate.length() == 1){
                    strDate = STRING_ZERO + strDate;
                }       
               
                yyyymmdd = strYear + STRING_SLASH + strMonth + STRING_SLASH + strDate;               
               
            }

            // To change correct format
            yyyymmdd = yyyymmdd.replace(STRING_SLASH, STRING_EMPTY);
            yyyymmdd = yyyymmdd.replace(STRING_HYPEN, STRING_EMPTY);
            yyyymmdd = yyyymmdd.replace(STRING_DOT, STRING_EMPTY);
            return yyyymmdd;           
    }     
   
    /**
     * To get the date from user and
     * remove the special char 
     * @param  String yyyymm
     * @return String yyyymm
     */
    public static String isYM(String yyyymm) {
       
       
        if(yyyymm.contains(STRING_SLASH)){
           
            String[] splitDate = yyyymm.split(STRING_SLASH);
           
            String strYear = splitDate[INT_ZERO];
            String strMonth = splitDate[INT_ONE];
           
            if(strMonth.length() == 1){
                strMonth = STRING_ZERO + strMonth;
            }
       
            yyyymm = strYear + STRING_SLASH + strMonth;               
           
        }   

            // To change correct format
            yyyymm = yyyymm.replace(STRING_SLASH, STRING_EMPTY);
            yyyymm = yyyymm.replace(STRING_HYPEN, STRING_EMPTY);
            yyyymm = yyyymm.replace(STRING_DOT, STRING_EMPTY);
            return yyyymm;           
    }   
   
    /**
     * To get the time from user and
     * remove the special char 
     * @param  String strTime
     * @return String strTime
     */
    public static String isTimeHM(String strTime) {

            // To change correct format
            strTime = strTime.replace(STRING_SLASH, STRING_EMPTY);
            strTime = strTime.replace(STRING_HYPEN, STRING_EMPTY);
            strTime = strTime.replace(STRING_DOT, STRING_EMPTY);
            strTime = strTime.replace(STRING_COLON, STRING_EMPTY);
            return strTime;           
    }   

    /**
     * To get the date from the user and
     * check the date is valid or not
     * @param date String
     * @return boolean returnBoolean
     */
    public static boolean isDateYYYYMMDD(String strDate) {
       
        boolean returnBoolean = true;
        if(strDate.length() > 10){
            returnBoolean = false;   
        }else if(strDate.length() < 8) {
            returnBoolean = false;   
        }else if(!strDate.contains(STRING_SLASH)){
            returnBoolean = false;               
        }else if(strDate.contains(STRING_SLASH)){
            String strTempDate = strDate.replaceAll(STRING_SLASH, STRING_EMPTY);       
           
            if(!isNumber(strTempDate)){               
                returnBoolean = false;
            }else if(!isValidDate(strDate)){
                returnBoolean = false;           
            }
        }else{
            if(strDate.length() == INT_EIGHT){
                String strTempDate = strDate.substring(INT_ZERO, INT_FOUR) + STRING_SLASH + strDate.substring(INT_FOUR, INT_SIX) 
                                                    + STRING_SLASH + strDate.substring(INT_SIX, INT_EIGHT);

                if(strDate.contains(STRING_SLASH)) {               
                    returnBoolean = false;
                }else if(!isNumber(strDate)){               
                    returnBoolean = false;
                }else if(!isValidDate(strTempDate)){
                    returnBoolean = false;               
                }
            }else{
                returnBoolean = false;   
            }
        }
       
        return returnBoolean;
    }
   
    /**
     * To get the date from the user and
     * check the date is valid or not
     * @param date String
     * @return boolean returnBoolean
     */
    public static boolean isDateYYYYMM(String strDate) {
       
        boolean returnBoolean = true;
       
        if(strDate.contains(STRING_SLASH)){
            String strTempDate = strDate.replaceAll(STRING_SLASH, STRING_EMPTY);       
           
            if(!isNumber(strTempDate)){               
                returnBoolean = false;
            }else if(!isValidYM(strDate)){
                returnBoolean = false;           
            }
        }else{
            if(strDate.length() == INT_SIX) {       
           
                String strTempDate = strDate.substring(INT_ZERO, INT_FOUR) + STRING_SLASH + strDate.substring(INT_FOUR, INT_SIX);
               
                if(strDate.contains(STRING_SLASH)) {               
                    returnBoolean = false;
                }else if(!isNumber(strDate)){               
                    returnBoolean = false;
                }else if(!isValidYM(strTempDate)){
                    returnBoolean = false;               
                }
            }else{
                returnBoolean = false;
            }
        }
       
        return returnBoolean;
    }
   

   
    /**
     * To get the Time from the user and
     * check the Time is valid or not
     * @param Time String
     * @return boolean returnBoolean
     */
    public static boolean isTimeHHMM(String strTime) {
       
        boolean returnBoolean = true;
       
        if (strTime.length() == INT_FIVE) {   
            String strTempTime = strTime.substring(INT_ZERO, INT_TWO) + strTime.substring(INT_THREE, INT_FOUR);
           
            if(!(strTime.charAt(INT_TWO) == CHAR_COLON)) {               
                returnBoolean = false;
            } else if(!isNumber(strTempTime)){               
                returnBoolean = false;
            }else if(!isValidTimeHM(strTime)){
                returnBoolean = false;           
            }
        } else if(strTime.length() == INT_FOUR) {       
           
            String strTempTime = strTime.substring(INT_ZERO, INT_TWO) + STRING_COLON + strTime.substring(INT_TWO, INT_FOUR);
           
            if(strTime.contains(STRING_COLON)) {               
                returnBoolean = false;
            }else if(!isNumber(strTime)){               
                returnBoolean = false;
            }else if(!isValidTimeHM(strTempTime)){
                returnBoolean = false;               
            }
        }else{
            returnBoolean = false;
        }
       
        return returnBoolean;
    }
       

   
    /**
     * Removing Date Seperator From Date
     * @param strValue
     * @return date in YYYYMMDD Format
     */
    public static String setDate(String strValue)  {
       
        if(isDateYYYYMMDD(strValue)){
            strValue = isDateYear(strValue);       
        }
        return strValue;
    }

    /**
     * Adding Date Seperator To Date
     * @param strValue
     * @return date in YYYY/MM/DD Format
     */
    public static String getDate(String strValue){
       
        if(strValue != null && strValue.length()== INT_EIGHT){
            strValue = strValue.substring(INT_ZERO, INT_FOUR)    + STRING_SLASH +strValue.substring(INT_FOUR, INT_SIX)
                                + STRING_SLASH +strValue.substring(INT_SIX, INT_EIGHT);   
        }
    return strValue;
    }
   
    /**
     * Removing Seperator From Year&Month
     * @param strValue
     * @return Year&Month in YYYYMM Format
     */   
    public static String setYM(String strValue)  {
       
        if(isDateYYYYMM(strValue)){
            strValue = isYM(strValue);       
        }
       
        return strValue;
    }

    /**
     * Adding Seperator From Year&Month
     * @param strValue
     * @return Year&Month in YYYY/MM Format
     */       
    public static String getYM(String strValue){
       
        if(strValue != null && strValue.length()== INT_SIX){
            strValue = strValue.substring(INT_ZERO, INT_FOUR)    + STRING_SLASH +strValue.substring(INT_FOUR, INT_SIX);   
        }
    return strValue;
    }   
   
    /**
     * Removing Seperator From Time
     * @param strValue
     * @return Time in HHMM Format
     */       
    public static String setTime(String strValue)  {
       
        if(isTimeHHMM(strValue)){
            strValue = isTimeHM(strValue);       
        }
        return strValue;
    }
   
    /**
     * Adding Seperator From Time
     * @param strValue
     * @return Time in HH:MM Format
     */           
    public static String getTime(String strValue){
       
        if(strValue != null && strValue.length()== INT_FOUR){
            strValue = strValue.substring(INT_ZERO, INT_TWO) + STRING_COLON + strValue.substring(INT_TWO, INT_FOUR);   
        }else if(strValue != null && strValue.length()> INT_FOUR){
            strValue = strValue.substring(INT_ZERO, INT_TWO) + STRING_COLON + strValue.substring(INT_TWO, INT_FOUR);
        }
    return strValue;
    }   
   
    /**
     * Check Input is Number or not
     * @param strInput
     * @return true/false
     */
    public static boolean isNumber(String strInput){
        if(strInput==null ||strInput.equals(STRING_EMPTY)){
            return false;
        }
        else{
          for(int intIndex = INT_ZERO; intIndex < strInput.length(); intIndex++){
              if ( !Character.isDigit(strInput.charAt(intIndex))){
                 return false;
              }
         }
         return true;
        }
       
    }
   
    /**
     * Check Input is Decimal or not
     * @param strInput
     * @return true/false
     */   
    public static boolean isDecimal(String strInput){
        boolean booReturn = false;
        if(strInput.contains(”.”)
                && (strInput.indexOf(”.”) == strInput.lastIndexOf(”.”))
                && (isNumber(strInput.replace(”.”, “”)))){
           
            booReturn = true;
           
        } else if(!strInput.contains(”.”)
                && (isNumber(strInput))){
            booReturn = true;
        }
        return booReturn;
       
    }
    /**
     * Check given String is date or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidDate(String strDate) {
       
       
        try{
            Date date = new Date(strDate);
               
            String[] splitDate = strDate.split(STRING_SLASH);
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
           
            String strYear = splitDate[INT_ZERO];
            String strMonth = splitDate[INT_ONE];       
            String strDay = splitDate[INT_TWO];           
           
            if(strYear == null || strYear.equals(STRING_EMPTY)){
                return false;
            }else if(strYear.length() != 4){
                return false;
            }else if(strMonth == null || strMonth.equals(STRING_EMPTY)){
                return false;
            }else if(strMonth.length() != 1 && strMonth.length() != 2){
                return false;       
            }else if(strDay == null || strDay.equals(STRING_EMPTY)){
                return false;
            }else if(strDay.length() != 1 && strDay.length() != 2){
                return false;                   
            }
           
            int intYear = Integer.parseInt(splitDate[INT_ZERO]);
            int intMonth = Integer.parseInt(splitDate[INT_ONE]) - INT_ONE;       
            int intDate = Integer.parseInt(splitDate[INT_TWO]);
           
            if(calendar.get(Calendar.DATE) != intDate){
                return false;
            } else if(calendar.get(Calendar.MONTH) != intMonth){
                return false;
            }else if(intYear > INT_9999 || intYear < 1000){
                return false;
            } else if(calendar.get(Calendar.YEAR) != intYear){
                return false;
            }
        }catch (Exception e) {
            return false;
        }
        return true;
    }
   

   
    /**
     * Check given String is Year&Month or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidYM(String strDate) {
       
       
        String[] splitDate = strDate.split(STRING_SLASH);
        if(splitDate != null && splitDate.length == 2){
            try{
                int intYear = Integer.parseInt(splitDate[INT_ZERO]);
                int intMonth = Integer.parseInt(splitDate[INT_ONE]);   
                       
                if(intMonth < INT_13 && intMonth > INT_ZERO && intYear < INT_9999 && intYear > INT_ZERO){
                    return true;
                } else {
                      return false;
                }
            }catch (Exception e) {
                return false;
            }
        }else{
            return false;
        }

    }   
   
    /**
     * Check given String is Time or not
     * @param strDate
     * @return true/false
     */
    public static boolean isValidTimeHM(String strTime) {
       
        String[] splitDate = strTime.split(STRING_COLON);
        if(splitDate != null && splitDate.length == 2){
            try{
                int intHour = Integer.parseInt(splitDate[INT_ZERO]);
                int intMinute = Integer.parseInt(splitDate[INT_ONE]);       
                if(intHour < INT_ZERO){
                    return false;
                } else if(intHour > INT_23){
                    return false;
                } else if(intMinute < INT_ZERO){
                    return false;
                } else if(intMinute > INT_59){
                    return false;           
                }
            }catch (Exception e) {
                return false;
            }               
        }else{
            return false;
        }       
        return true;
    }   
   

   
    /**
     * Checks Two Date (End Date Greater Than From Date)
     * @param strFromDate
     * @param strToDate
     * @return true/false
     * @throws ParseException
     */
    public static boolean CompareDate(String strFromDate, String strToDate) throws ParseException {
        boolean booFlag = true;
        if(isDateYYYYMMDD(strFromDate) && isDateYYYYMMDD(strToDate)) {
            if(!strFromDate.equals(strToDate)) {
                Date FromDate = getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).parse(setDate(strFromDate));
                Date ToDate = getDateFormat(STRING_DATE_FORMAT_YYYYMMDD).parse(setDate(strToDate));
                booFlag = FromDate.before(ToDate);
            }
        }
        return booFlag;
    }

}

OK, Now leave me the comments or sugesstion in my comment box.

Thanking you for using my Codes

 
 
PDF Generation with Japanese font


Most of the Web based Work flow projects are having the option for viewing the searched result as PDF file which allow saving the PDF in locally. For PDF generation, itext API is the best choice, since it is an Open source.

When I developing an application I have faced problem in viewing Japanese font in PDF, after spending more time on it, I got solution for it.

In itext API, there is a class called ‘BaseFont’. The Font-object returned by the FontFactory is in many cases just a wrapper class for the more complex class BaseFont. We can create such a basefont directly by using one of the BaseFont.createFont methods. Below I have written the simple POJO program which displays the japanese fonts in PDF.

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.BaseFont;

public class GeneratePDF {
    public static void main(String[] args) {
        Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream(”jpn_Vijay.pdf”));
            document.open();
            BaseFont bFontJapanese = BaseFont.createFont(”KozMinPro-Regular”,
                    “UniJIS-UCS2-H”, BaseFont.NOT_EMBEDDED);
            Font font = new Font(bFontJapanese, 12, Font.NORMAL);

            document.add(new Paragraph(”私はIVTLのビジェイです。”, font));

            PdfPTable table = new PdfPTable(3);
            for (int i = 0; i < 9; i++) {

                PdfPCell cell = new PdfPCell();
                cell.setColspan(3);
                cell.addElement(new Paragraph(”日本にいきたいです”, font));
                table.addCell(cell);
            }
            document.add(table);

        } catch (DocumentException de) {
            System.err.println(”Doc exception…” + de.getMessage());
        } catch (IOException ioe) {
            System.err.println(”IO exception…” + ioe.getMessage());
        }
        document.close();
    }
}

Now it’s your turn. Just share your valuable ideas by commenting in this article. 

 
 
Solution for Downloading Japanese Fonts in CSV file

Web applications have the option to download the search result as CSV file. This is a big problem that most programmers facing when downloading CSV file with Japanese Characters. Normally, we just set UTF-8 encoding for Japanese Characters. But, CSV files will unable to detect that utf-8 encoding. Here I have given the correct solution for this problem. This Program will download the data as CSV with Japanese Characters also. It have tested and implemented.

image

First, set the properties for HttpServletResponse’s Object,

response.setContentType(”application/octet-stream;charset=WINDOWS-932″);
    response.setCharacterEncoding(”WINDOWS-932″);
    response.setHeader(”Content-Disposition”, “attachment; filename=”
        + URLEncoder.encode(fileName, “WINDOWS-932″));

Then, Create PrintWriter’s object,
    OutputStreamWriter osw = new OutputStreamWriter(response
                .getOutputStream());
    PrintWriter out = new PrintWriter(osw);

   
And then, you just have to use this below method. This String strData should contain the data which is to be downloading as CSV.

public HttpServletResponse download(String strData) throws IOException {
try {
InputStream in = new ByteArrayInputStream(strData.toString()
                    .getBytes(”WINDOWS-932″));
    byte[] inputByte = strData.toString().getBytes(”WINDOWS-932″);       

 

   ServletOutputStream sosout = response.getOutputStream();
    byte[] outputByte = new byte[inputByte.length];
    // copy binary contect to output stream
    while (in.read(outputByte, 0, inputByte.length) != -1) {
        sosout.write(outputByte, 0, inputByte.length);
        }
    in.close();
    sosout.flush();
    sosout.close();
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
}
return response;
}

 

Note:Please Leave your Valuable Comments.

 
 
10 Tips for Project Success

image

Project success is too often defined as “on time and on budget”.  In a larger sense, true project success is an intangible, realized through consensus, collaboration and communication. I have found out 10 Tips for Project Success. I would like to share with you also. Read and share your thoughts to the world also by giving comments to this article.

  1. Starting out: Make sure that when you start out your customer defines their requirements in depth. You need to know exactly what it is that must be delivered, to who and when. Make it specific, write it up formally and get them to sign it off. This document will become the basis upon which to measure your success.

  2. Customers: Involve your customers throughout the entire project life cycle. Get them involved in the analysis and planning, as well as execution. You don’t have to seek their approval, just keep them informed. The more you involve them, the greater their level of buy-in and the easier it is to manage their expectations.

  3. Timeframes: Keep your delivery timeframes short and realistic. Never agree to lengthy timeframes. Split the project into “mini-projects” if you need to. Keep each mini-project to less than 6 months. This keeps everyone motivated and focused.

  4. Milestones: Break your project timeframe into “Milestones” which are manageable pieces of work. Add delivery deadlines to your milestones and try to deliver on every deadline, no matter what. If you’re late, tell your customer about it as early as possible.

  5. Communications: Make sure you keep everyone informed by providing the right information at the right time. Produce Weekly Status Reports and run regular team meetings.

  6. Scope: Only authorize changes to your project scope if there is no impact on the timeline. Get your customers approval to important scope changes first and then get their buy-in to extend the delivery dates if you need to.

  7. Quality: Keep the quality of your deliverables as high as possible. Constantly review quality and never let it slip. Implement “peer reviews” so that team members can review each others deliverables. Then put in place external reviews to ensure that the quality of the solution meets your customer’s needs.

  8. Issues: Jump on risks and issues as soon as they are identified. Prioritize and resolve them before they impact on your project. Take pride in keeping risks and issues to a minimum.

  9. Deliverables: As each deliverable is complete, hand it formally over to your customer. Get them to sign an Acceptance Form to say that it meets their expectations. Only then can you mark each deliverable off as 100% complete.

  10. Your team: Great projects are run by great teams. Spend the time to find the right people. It will save you time down the track. Remember, good people are easy to motivate. Show them the vision and how they can make it happen. Trust and believe in them. Make them feel valued. They will work wonders.

And that’s it. With these 10 tips you can boost your project success.

 
 
Will Ruby Beat Java???

 image

Ruby is a new language from Japan is quickly gaining interest. Ruby's creator, Yukihiro Matsumoto has successfully released 2003. Within a short period it becomes popular and powerful as java. To reach this level, Java has taken around 10 years of period. But, Ruby just reaches within 3 years after released the English version of Documentation.

The TIOBE index, which is measures the growth of programming languages, ranks Ruby as #5 among programming languages worldwide. Much of the growth is attributed to the popularity of software written in Ruby, particularly the Ruby on Rails web framework.

It is a powerful and dynamic open source, object-oriented language which runs on many platforms, including Linux and many flavors of UNIX, MS-DOS, Windows 9x/2000/NT, BeOS, and MacOS X. 

Ruby's primary focus is productivity of program development, and users will find that programming in Ruby is productive and even fun.

Ruby is productive and even fun. Ruby is well suited for the problem domains such as these:
Text processing—Ruby's File, String, and Regexp classes help you process text data quickly and cleanly.
CGI programming—Ruby has everything you need to do CGI programming, including text-handling classes, a CGI library, and database interface, and even eRuby (embedded Ruby) and mod_ruby for Apache.
Network programming—Network programming can be fun with Ruby's well-designed socket classes.
GUI programming—GUI tool kit interfaces such as Ruby/Tk and Ruby/Gtk are available.
XML programming—Text-handling features and the UTF-8-aware regular expression engine make XML programming handy in Ruby. The interface to the expert XML parser library is also available.
Prototyping—with its high productivity, Ruby is often used to make prototypes. Prototypes sometimes become production systems by replacing the bottlenecks with C written extensions.
Programming education—you can teach students that programming is fun

 

Now world is turns from Java to Ruby for developing the project. Some of the Successful stories about Ruby’s Victory.

  • NASA Langley Research Center uses Ruby to conduct simulations. 
  • A research group in Motorola uses Ruby to script a simulator, both to generate scenarios and to post process the data.
  • Google SketchUp is a 3D modeling application that uses Ruby for its macro scripting API. 
  • Toronto Rehab uses a RubyWebDialogs based app to manage and track on-call and on-site support for the IT help desk and IT operations teams. 
  • 43 Things allows you to keep a list of goals and share it with the world. It was developed entirely in Ruby.  
 
 
SQL Injection

 image

SQL injection is a technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is in fact an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another.
Real Time Examples
  • On October 26, 2005, Unknown Heise readers replaced a page by the German TV station ARD which advertised a pro-RIAA sitcom with Goatse using SQL injection.
  • On November 01, 2005, A high school student used a SQL injection to break into the site of a Taiwanese information security magazine from the Tech Target group and steal customer's information.
  • On January 13, 2006, Russian hackers broke into a Rhode Island government web site and allegedly stole credit card data from individuals who have done business online with state agencies.
  • On June 29, 2007, Hacker Defaces Microsoft U.K. Web Page using SQL injection.
  • In May 2008, a server farm inside China used automated queries to Google's search engine to identify SQL server websites which were vulnerable to the attack of an automated SQL injection tool.
Preventing SQL Injection
 To protect against SQL injection, user input must not directly be embedded in SQL statements. Instead, user input must be escaped, filtered, or parameterized statements must be used.
Using Parameterized Statements.
In Java parameterized statements can be used that work with parameters (sometimes called placeholders or bind variables) instead of embedding user input in the statement. In many cases, the SQL statement is fixed. The user input is then assigned (bound) to a parameter. This is an example using Java and the JDBC API:
PreparedStatement prep = conn.prepareStatement("SELECT * FROM USERS WHERE USERNAME=? AND PASSWORD=?");
prep.setString(1, username);
prep.setString(2, password);
 
 
Top 10 Mistakes that Java Developers have Done

image

Even though a Experiecnced Java Programmer also Do these kind of mistakes while doing project.

10. Accessing non-static member variables from static methods (such as main)
9. Mistyping the name of a method when overriding
8. Comparison assignment (  = rather than == )
7. Comparing two objects ( == instead of .equals)
6. Confusion over passing by value, and passing by reference
5. Writing blank exception handlers
4. Forgetting that Java is zero-indexed
3. Preventing concurrent access to shared variables by threads
2. Capitalization errors
And the number one error that Java programmers make !!!!!
1. Null pointers!

 

 
 
BackBone of Java

                                       image                          

Collection is a Back Bone of Java. In Real Time Development, it acts a very big role. I just Give you Some Valuable Tips about Collections while use in Real Time Projects.

Lists:

  • Use ArrayList with proper initialization if you don't want thread safe for the collection whenever you  add/remove/access objects at end and middle of collection.
  • Use Vector with proper initialization if you want thread safe for the collection whenever you  add/remove/access objects at end and middle of collection.
  • Use LinkedList if you don't want thread safe for the collection whenever you  add/remove/access objects at beginning of collection.
  • Use synchronized LinkedList if you want thread safe for the collection whenever you add/remove/access objects at beginning of collection.
  • Use ListIterator than Iterator and Enumeration for List types

Sets:

  • Use HashSet for maintaining unique objects if you don't want thread safe for the collection for all basic(add/remove/access) operations otherwise use synchronized HashSet for thread safe.
  • Use TreeSet for ordered and sorted set of unique objects for non-thread safe collection otherwise use synchronized TreeSet for thread safe 

Maps:

  • Use HashMap for non-thread safe map collection otherwise use Hashtable for thread safe collection.
  • Use TreeMap for non-thread safe ordered map collection otherwise use synchronized TreeMap for thread safe.

 

 
 
  
 
   
 
   About Me  
 
A Passionate java programmer and web developer. Prefer me judjing myself rather than other's doing it..
More »
 
   My SweetCircles  
 
 
   My Forum  
 
 
   Gossipad: Say to me  
 
 
Recent Gossips
  Wishing you advanced birthday wishes
  Hello Dearest Friend How are you today? Hope fine...
  hi friend hou u r .
More »
 
    Archives  
 
 
    My Favorite Links  
 
 
   I have Blogged about  
 
 
    My Blog's Feed  
 
RSS Feed
   
   
powered by sweetcircles.com
   
   
  11866