Posts

Showing posts from March, 2017

Scheduler in java.

Image
Run task periodically in java or Scheduler in java. FILE :  SchedulerMain.java package com.codeFactory; import java.util.Date; import java.util.TimerTask; public class SchedulerMain extends TimerTask{ Date current; int cnt=0; @Override public void run() { current = new Date(); System.out.println("Current Date and Time : " + current); cnt++; if(cnt==5) { System.out.println("EXIT."); System.exit(0); } } } FILE :  SchedulerCall.java package com.codeFactory; import java.util.Timer; public class SchedulerCall { public static void main(String args[]) { Timer time = new Timer(); SchedulerMain scMain = new SchedulerMain(); time.schedule(scMain, 0, 5000); } }

How to check String is a valid date or not in java | Code Factory

Image
Check String value is a valid date or not. package com.codeFactory; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { public static boolean checkDate(String inDate) { /* SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); */ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); try { dateFormat.parse(inDate.trim()); } catch (ParseException pe) { return false; } return true; } public static void main(String[] args) { /* System.out.println(isValidDate("30-03-2017")); */ System.out.println(checkDate("2017-02-28")); } }

DisplayTag with Struts2 | Code Factory

Image
Part 1 : Part 2 : Download code and jars :  Link. File : emp.java package com.codeFactory; public class emp { private String name; private String email; public emp(String name, String email) { this.name = name; this.email = email; } public String getName() { return name; } public String getEmail() { return email; } } File :  getData .java package com.codeFactory; package com.codeFactory; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.interceptor.ServletRequestAware; import com.opensymphony.xwork2.ActionSupport; public class getData extends ActionSupport implements ServletRequestAware{ HttpServletRequest request; public String execute() { List<emp> empList = new ArrayList<emp>(); empList.add(new emp("parth", "parth@p.co")); empList.add(new emp("patel", "patel@p.co")); empList.add(new emp(