Wednesday, August 17, 2011

50 Best websites by Time!

Time magazine recently published best 50 websites for year 2011. 50 Best Websites 2011 Out of these 50 sites, I find below ones are most interesting for day-2-day life.


My Top 10 Favorites of Best Websites
Web Site What For?
8Tracks Good Mucic collection for streaming. All high quality legal tracks
HowCast Videos of how to of many things
MyDamnChannel Lots of interesting short films
BigThink Experts view on science, future, arts, business and much more
GetHuman Way to get a real person not a voice menu from Customer Service
Instapaper A simple tool to save web pages for reading later.
ScienceDaily Daily Science news
Join Me share your Windows PC or Mac's desktop with others
ZenHabits Eye opening life lessons
KhanAcademy Lots of study materials on all subjects

Tuesday, August 16, 2011

Tuesday, August 9, 2011

Code Katas

David Thomas of Pragmatic Programmer [pragprog] says, "Most of other professional do practice before perform.. Artists, musicians and even physicians.. But programmers do all practice on the job. No wonder how many defects we leave at work"

Practice to become a better programmer.

A set of interesting experiments every programmer should complete to move ahead towards that goal.

Code Kata



Monday, August 1, 2011

First touch of Java 7

Java 7 is here... and there are many improvements. But as a developer, what we can use on day to day use.. 

1. Strings in Switch 
  - Long waited feature. Makes life much simpler in many ways. Till Java 5, the handling was terrible by defining constants integers or characters and we tend to improve with enums on Java 5 and now finally to match with real world identities 

2. Multi catch exceptions
 Another graceful feature. Reduces lot of code duplication.

3. Try with resources.
   Whenever we access resources we do with try catch finally block, where we release the resources [closing the connections etc] at finally block. With this feature, there will be no need of such finally blocks. The resources on try will automatically released after the try block resulting in much cleaner code.

There are much more with collections, file API, and concurrency features. Will update soon. 

package org.nava.java7;


import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import static java.lang.System.out;


/**
 *
 * @author nadhimoolam
 */
public class ProjectCoinTest {


    public static void main(String args[]) {
        String condition = "BLue";
        testSwitch(condition);
        tryWithMulti();
        tryWithResources(new File("source"), new File("target"));
    }


    private static void testSwitch(String condition) {
        switch (condition.toLowerCase()) {
            case "blue":
            case "red":
                out.println("The choice is " + condition);
                break;
            default:
                out.println("Default ");
        }


    }


    private static void tryWithMulti() {
        try {
            File f = new File("Is this file exists ");
            throw new FileNotFoundException();
        } catch (NullPointerException | FileNotFoundException e) {
            out.println("It should be either null pointer or file not found " + e);
        } catch (Throwable t) {
            out.println("Its throwable now  " + t);
        } finally {
            out.println("Finally.");
        }
    }


    private static void tryWithResources(File source, File target) {
        try (InputStream fis = new FileInputStream(source);
                OutputStream fos = new FileOutputStream(target)) {


            byte[] buf = new byte[8192];


            int i;
            while ((i = fis.read(buf)) != -1) {
                fos.write(buf, 0, i);
            }
        } catch (Exception e) {
            out.println("Exception on trying the resources..." + e);
        }
    }
}