Blog Archives

Parsing CronJob Expression in Android

I had been trying to parse a cron expression string in my Android app and came across this CronExpression Code source code. I move it into my project and you can just use it off the shelve by calling

CronExpression conExpression = new CronExpression(“* * 10 * * ?”); // This will construct a cronjob which runs at 10am daily.

After obtaining the object, you can explore to more method that it provides for your business logic.


Simple method to generate random password

   public static String generateTempPassword(int length){
	   String character = "qwertyuioplkjhgfdsazxcvbnm1234567890POIUYTREWQASDFGHJKLMNBVCXZ!@#$%&";
	   StringBuffer sb = new StringBuffer();
		   double index = Math.random() * character.length();
	   return sb.toString();

Getting Date information from MongoDB’s document objectid

This post is for mongodb java api only.

	private Date getTimeStampFromID() {
        DB db = connectDB();
        DBCollection collection = db.getCollectionFromString("database");
		DBCursor cursor = collection.find();
			return (new Date(((ObjectId);

Parsing JSON data using Google GSON library in Eclipse

1. Download gson library
2. Add as external jar from your eclipse project

JSON String:
[{“ID”:”18″, “Name”:”Name A”} ,
{“ID”:”19″, “Name”:”Name B”} ,
{“ID”:”20″, “Name”:”Name C”} ,
{“ID”:”21″, “Name”:”Name D”}]

Java class to implement the parsing

public class gsonexample {

	public gsonexample(){}

	public void parseJson(String url){
			Reader reader = new InputStreamReader(new URL("url").openStream()); //Read the json output
			Gson gson = new GsonBuilder().create();
			DataObject obj = gson.fromJson(reader, DataObject.class);
		}catch(Exception e){

	private class DataObject{ //This class should match your json object structure
		private int status;
		private String error_message;
		private List<Item> item; // This is for the inner array
	    public String toString() {
	        return status + " - " + error_message+ " (" + item + ")";

	private class Item{ //This is the inner array class
		public int ID;
		public String Name;
	    public String toString() {
	        return ID + " - " + Name +"\n";

Convert integer array to integer

This is a simple function on how one can convert an integer array (int[]) to integer value

public int add(int[] array) {
int len = array.length;
int tmp = 0;
for(int i: array){
tmp += i*((int)Math.pow(10,--len));

return tmp;

Exception java.util.ConcurrentModificationException on ArrayList

If you encounter exception:

Exception in thread “main” java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(
at java.util.AbstractList$

You can go around and use CopyOnWriteArrayList<E>() instead.