Tuesday 22 September 2015

Java 1.8 features....


1. One of the main difference is introduction of static and default methods in interface. This will gradually obsolete  the use of abstract classes in java


reference ; http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html

example :

public interface HasFieldValue<T>
{
    T getFieldValue();

    static <T> String getFieldAsString( HasFieldValue<T> hasFieldValue )
    {
        return ( hasFieldValue != null ) ? hasFieldValue.getFieldValue().toString() : "";
    }

    static <R extends HasFieldValue<V>, V> R fromValue( R[] possibleResultValues, V fieldValue )
    {
        if ( fieldValue != null )
        {
            for ( R resultValue : possibleResultValues )
            {
                if ( resultValue.getFieldValue().toString().equals( fieldValue.toString() ) )
                {
                    return resultValue;
                }
            }
        }
       
    

    default Object getDefaultForEmptyField()
    {
        throw new IllegalArgumentException( "Field cannot be blank" );
    }
}

2. lamba expressions..

Monday 10 November 2014

Newyork times used Hadoop to archive data..



Newyork times used Hadoop to archive data..

The technology is moving fast & efficient.

The New York Times using Hadoop to convert about 4 million entities to PDF
in just under 36 hours


http://timesmachine.nytimes.com/timesmachine/1912/04/16/p/1

Wednesday 24 September 2014

India scripts history, becomes the first country to send Mars Orbiter in first attempt



Cost - $71 million which is $29 million less than the cost of hollywood movie GRAVITY.

Is't it amazing?


Read more in

http://indianexpress.com/article/india/india-others/india-succeeds-putting-spacecraft-in-martian-orbit/

Wednesday 3 September 2014

Java Program for calculating business days considering public holidays

This is in continuation to my previous post...

This is a Java Program for calculating business days considering public holidays

public long getNumberOfBusinessDays(Date start, Date end) 
    {
        if (start == null || end == null)  
            return 0;

        long daysWithoutSunday = 0;
        int w1 = 0;
        int w2 = 0;
        long actualNumberOfBusinessDays = 0;
        
        Calendar c1 = GregorianCalendar.getInstance();
        c1.setTime(start);
        w1 = c1.get(Calendar.DAY_OF_WEEK);
        c1.add(Calendar.DAY_OF_WEEK, -w1 + 1);

        Calendar c2 = GregorianCalendar.getInstance();
        c2.setTime(end);
        w2 = c2.get(Calendar.DAY_OF_WEEK);
        c2.add(Calendar.DAY_OF_WEEK, -w2 + 1);

        //end Saturday to start Saturday 
        long days = (c2.getTimeInMillis() - c1.getTimeInMillis())/(1000*60*60*24);
        
        daysWithoutSunday = days-(days*2/7);

        if (w1 == Calendar.SUNDAY) 
            w1 = Calendar.MONDAY;
        
        if (w2 == Calendar.SUNDAY) 
            w2 = Calendar.MONDAY;
       
       /*
             * Check if the there are dates which are falling in public holidays?
             * Currently handling only Christmas & New Year days.
             */
            long numberOfBusinessDaysWithoutSundayAndSaturday = daysWithoutSunday - w1 + w2;
            actualNumberOfBusinessDays = numberOfBusinessDaysWithoutSundayAndSaturday;

            while (numberOfBusinessDaysWithoutSundayAndSaturday > 0 && start.before(end))
            {
                if (isPublicHoliday(start))
                    actualNumberOfBusinessDays -= 1;
                start = addDay(start);
                numberOfBusinessDaysWithoutSundayAndSaturday -= 1;
            }
            return actualNumberOfBusinessDays;
    }
    public static boolean isPublicHoliday(Date date) 
    {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int w1 = cal.get(Calendar.DAY_OF_WEEK);
        
        // check if New Year's Day & not falls on a Saturday or Sunday because weekends are already taken care
        if (cal.get(Calendar.MONTH) == Calendar.JANUARY && cal.get(Calendar.DAY_OF_MONTH) == 1 && w1 != Calendar.SUNDAY && w1 != Calendar.SATURDAY) 
            return true;

        // check if Christmas & not falls on a Saturday or Sunday because weekends are already taken care
        if (cal.get(Calendar.MONTH) == Calendar.DECEMBER && cal.get(Calendar.DAY_OF_MONTH) == 25 && w1 != Calendar.SUNDAY && w1 != Calendar.SATURDAY) 
            return true;
        return false;

    }
    private static Date addDay(Date date)
    {
        Calendar cal = Calendar.getInstance();
        cal.setTime (date);
        cal.add (Calendar.DATE, 1);
        return cal.getTime();
     }

Java program to calculate the number of business days between two dates.

This is a Java program to calculate the  number of business days between two dates..
This program will exclude only Saturdays & Sundays and not the public holidays.

public long getNumberOfBusinessDays(Date start, Date end) 
    {
        if (start == null || end == null)  
            return 0;

        long daysWithoutSunday = 0;
        int w1 = 0;
        int w2 = 0;
        
        Calendar c1 = GregorianCalendar.getInstance();
        c1.setTime(start);
        w1 = c1.get(Calendar.DAY_OF_WEEK);
        c1.add(Calendar.DAY_OF_WEEK, -w1 + 1);

        Calendar c2 = GregorianCalendar.getInstance();
        c2.setTime(end);
        w2 = c2.get(Calendar.DAY_OF_WEEK);
        c2.add(Calendar.DAY_OF_WEEK, -w2 + 1);

        //end Saturday to start Saturday 
        long days = (c2.getTimeInMillis() - c1.getTimeInMillis())/(1000*60*60*24);
        
        daysWithoutSunday = days-(days*2/7);

        if (w1 == Calendar.SUNDAY) 
            w1 = Calendar.MONDAY;
        
        if (w2 == Calendar.SUNDAY) 
            w2 = Calendar.MONDAY;
       
        return daysWithoutSunday-w1+w2;
    }
 

Monday 21 July 2014

Good for Java Interview Preparations

I found this in internet which I think very useful. This is not a promotional stuff, but for my reference.

http://java-success.blogspot.co.uk/2014/06/top-50-core-java-interview-questions.html

Wednesday 9 July 2014

how to clean up svn when crashed

There are times when we see the blow error in your svn or cygwin tool

svn: Working copy ‘/myrepo/repodirectory’ locked
svn: run ’svn cleanup’ to remove locks (type ’svn help cleanup’ for details)

if you run  svn status at this stage you will see all the files & folders will have a  "L" , meaning,  it is locked.

The easiest way to resolve this issue is to provide the below command in the command prompt
(assuming that the command is executed from the root of the workspace
svn cleanup .      

The above command will basically unlock all the folders/subfolder and files recursively.