
With this video I intended to express 3 things :
- How we execute the sample in Eclipse environment
- The running class will create a HTTPS channel
- Execution result is immediately visible to us

if(textToBeMatched.matches("[a-z A-Z]+"))
System.out.println("Text match with a series of alphabet and space character only pattern");
public class RegexTest {
public static void testPhoneNumber(String phoneNumber)
{
String phoneNumberPattern = "^\\+{0,1}[\\d]+[-\\d]+\\d$";
if(phoneNumber.matches(phoneNumberPattern))
System.out.println(phoneNumber + " is a correct phone number !");
else
System.out.println(phoneNumber + " is a wrong phone number !");
}
public static void main(String[] args)
{
testPhoneNumber("+6221-3011-9353"); //outputs a correct phone number
testPhoneNumber("-6221-3011-9353"); //outputs a wrong phone number
}
}

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexReplacementTest {
public static String censoredPhoneNumber(String phoneNumber)
{
String phonePattern = "(\\+{0,1}[\\d]+[-\\d]+\\d).*";
Pattern pattern = Pattern.compile(phonePattern);
Matcher matcher = pattern.matcher(phoneNumber);
return matcher.replaceAll("*censored*");
}
public static void main(String[] args)
{
String phoneNo = "My phone number is +6221-3011-9353";
System.out.println(censoredPhoneNumber(phoneNo));
}
}
Date now = new Date();
long nowLong = now.getTime(); //returning a timestamp
System.out.println("Value is " + nowLong);
SimpleDateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy");
Date now = new Date();
long nowLong = now.getTime(); //returning a timestamp
System.out.println(df.format(now));
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
try {
Date date = (Date) sdf.parse("12/31/2007");
System.out.println("Current date is : " + sdf.format(date));
} catch (ParseException e) {
System.out.print("Illegal date !");
}
//With compareTo() method we should have a return of value -1, 0, and 1.
//Syntax : date1.compareTo(date2);
//Return value
// -1 : date1 is earlier than date2
// 0 : date1 is having exactly same value with date2
// 1 : date2 is later than date2
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
try {
Date date1 = (Date) sdf.parse("12/31/2007");
Date date2 = (Date) sdf.parse("12/31/2008");
Date date3 = (Date) sdf.parse("12/31/2008");
System.out.println(date1.compareTo(date2));
System.out.println(date2.compareTo(date1));
System.out.println(date2.compareTo(date3));
} catch (ParseException e) {
System.out.print("Illegal date !");
}
//Get current date and time
Calendar cal = new GregorianCalendar();
System.out.println(cal);
//Set date with int value
Calendar newdate = new GregorianCalendar(2008, Calendar.MARCH, 1);
System.out.println(newdate);
//Convert into Date object
Date date = newdate.getTime();
System.out.println(date);
//Print with a MM/dd/yyyy format
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("New date is : " + sdf.format(date));