How to validate date in Java using Regular Expressions

The following java program has the capability of doing the date format validation in software using regular expressions and is able to validate both mmddyyyy and ddmmyyyy date formats (of course the date, month and year can be separated using punctuations or delimiters).

package com.kushal.tools;
/**
 * @author Kushal Paudyal
 * Last Modified on 2010/12/21
 * 
 * This class demonstrates the use of regular expressions to validate Dates
 * It basically validates two formats of dates:MMDDYYYY & DDMMYYYY
 * Both of these validations accept -, / and . as delimiters.
 * 
 * www.sanjaal.com/java
 */

import java.util.regex.Pattern;

public class DateValidatorRegex {
	
	static String regexMMDDYYYY="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$";
	static String regexDDMMYYYY="^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d$";
	
	public static void main (String [] args ) {
		/**Testing for MMDDYYYY**/
		System.out.println("TEST FOR MMDDYYYY");
		System.out.println(isAValidMMDDYYYYDate("07-20-1982"));//true
		System.out.println(isAValidMMDDYYYYDate("07/20/1982"));//true
		System.out.println(isAValidMMDDYYYYDate("07.20.1982"));//true
		System.out.println(isAValidMMDDYYYYDate("07201982"));//false
		System.out.println(isAValidMMDDYYYYDate("20.07.1982"));//false
		
		/**Testing for MMDDYYYY**/
		System.out.println("\nTEST FOR DDMMYYYY");
		System.out.println(isAValidDDMMYYYYDate("20-07-1982"));//true
		System.out.println(isAValidDDMMYYYYDate("20/07/1982"));//true
		System.out.println(isAValidDDMMYYYYDate("20.07.1982"));//true
		System.out.println(isAValidDDMMYYYYDate("20071982"));//false
		System.out.println(isAValidDDMMYYYYDate("07.20.1982"));//false
		
	}
	/**
	 * @param date
	 * MMDDYYYY DATE VALIDATION
	 * It can validate the following three kinds of dates:
	 * 07-20-1982
	 * 07/20/1982
	 * 07.20.2982
	 */
	public static boolean isAValidMMDDYYYYDate(String date) {
		return Pattern.matches(regexMMDDYYYY, date);
	}
	
	/**
	 * @param date
	 * DDMMYYYY DATE VALIDATION
	 * It can validate the following three formats of dates:
	 * 20-07-1982
	 * 20/07/1982
	 * 20.07.1982
	 */
	public static boolean isAValidDDMMYYYYDate(String date)	{
		return Pattern.matches(regexDDMMYYYY, date);
	}
}

Roles and Responsibilities of Business Product Owner in Agile Teams

Product owner is one of the most important roles in any agile teams. Sometimes this role is also called BPO referring to Business Product Owner. Product owner is one of the three key roles of the agile team (namely Product Owner, Scrum Master & The Team) and is a someone tasked with creating vision for the product and governing what is being released.

Here are some of the key roles a product owner typically does in an agile team.

  1. Defines the features of the product being developed by conveying or creating the vision and goals
  2. Creates and maintains the product backlog
  3. Prioritizes the features according business or market values so that they are analyzed, developed and tested according to those priorities
  4. Helps the team if any clarifications are required around the features /epics or stories.
  5. Is responsible for the profitability of the product.
  6. Is responsible for making any adjustment to the features being developed for the priority of the development every iteration as needed.
  7. Participates in the various key meetings such as Daily Scrums, Retrospectives, and probably explains the business values to the stakeholders when a Show and Tell meeting is conducted.
  8. Makes decision on acceptance or rejection of the work results
  9. Represents the customer and engages the customers or interfaces with them as required.
  10. Is responsible for communicates the project status to external stakeholders
  11. Has authority to terminate the iteration or sprint if a sudden change in direction is required.

On the fun side, also take a look at the following two great cartoons about product owner roles. (Disclaimer: The images have been borrowed under fair usage. The original author name(s) appear on the cartoon itself)

First one:

An the other one:

Writing To Excel File Using Apache POI

This is a java tutorial where I have demonstrated how to use Apache POI to write data to any excel/spread sheet. The program handles HSSF model of spreadsheet.

/**
 * @author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified on 02/16/2008
 */
package com.kushal.util;

import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class CreateExcelFile {
 
    public static void main( String [] args ) {
    	/**Name of excel file that we are going to create**/
    	String fileName="C:\temp\testPOIWrite.xls";
    	writeDataToExcelFile(fileName);    
    }
    /** This method writes data to new excel file **/
	 private static void writeDataToExcelFile(String fileName) {
		 
	     String [][] excelData = preapreDataToWriteToExcel();		 
			 
		 HSSFWorkbook myWorkBook = new HSSFWorkbook();
		 HSSFSheet mySheet = myWorkBook.createSheet();
		 HSSFRow myRow = null;
		 HSSFCell myCell = null;
		
		 for (int rowNum = 0; rowNum < excelData[0].length; rowNum++){    
			 myRow = mySheet.createRow(rowNum);
			 
			 for (int cellNum = 0; cellNum < 4 ; cellNum++){
		         myCell = myRow.createCell(cellNum);
		         myCell.setCellValue(excelData[rowNum][cellNum]);      
		       
		     }
		 }
		 
		 try{
			 FileOutputStream out = new FileOutputStream(fileName);
			 myWorkBook.write(out);
			 out.close();
		 }catch(Exception e){ e.printStackTrace();}			
		
	}
	 /**Prepare some demo data as excel file content**/
	 public static String [][] preapreDataToWriteToExcel(){
		 String [][] excelData = new String [4][4];
		 excelData[0][0]="First Name";
		 excelData [0][1]="Last Name";
		 excelData[0][2]="Telephone";
		 excelData[0][3]="Address";
		 
		 excelData[1][0]="Kushal";
		 excelData[1][1]="Paudyal";
		 excelData[1][2]="000-000-0000";
		 excelData[1][3]="IL,USA";
		 
		 excelData[2][0]="Randy";
		 excelData[2][1]="Ram Robinson";
		 excelData[2][2]="111-111-1111";
		 excelData[2][3]="TX, USA";
		 
		 excelData[3][0]="Phil";
		 excelData[3][1]="Collins";
		 excelData[3][2]="222-222-2222";
		 excelData[3][3]="NY, USA";
		 
		 return excelData;
		 
	 }	
    
}