Wednesday, September 12, 2012

Java blogs -- Internals about Java -- Has lot of info -- All about SCJP

Top Java Blogs

Best Java Websites

1) Has Best Java Tutorials. One can also find tutorials on Java EE related technologies and frameworks. The website has tutorials for struts, spring, hibernate and everything related to Java.
2) Get certified on Java for free. Increase your knowledgeg by giving some Java exams and then contribute to create questions for the new comers to the community. One of the bst website for Java.
3) Read Java interview questions. Get real time interview questions asked in Java interviews. Helps you in getting that dream job as a Java developer.
4) Has various Java articles and programming news. A lot of developers and architects contribute to this wonderful Java community. Read articles, news, opinions and interviews of Java experts.
5) A great initiative to provide quality tutorials and material on Java related technologies. Has articles covering almost everything in the world of Java.
6) Basically a community for official Java certification with Java developers who put their hands on creating the Java certification exam at Sun. Very much active and you can look forward to get answer to almost all questions on this forum.
7) A very sophisticated Java community which publishes articles and news related to enterprise Java. Very frequently updated and visited by almost all Java developers.
8) Ask and answer java questions. Has categories to ask any kind of question related to Java. Very active java forums and members quickly answer your Java queries. A must visit for Java developers at all levels.
9) The official page for Java tutorials. Almost all topics in JDK are covered with illustrative examples.Also the best place to download the latest version of JDK.
10) IBM is a major contributor to the Java language. The consultants at IBM post articles related all topics on this great Java platform. One of the Best Java Websites to visit.

GWT Blogs

Supply Chain Technology; why can't I promote our own blog?  You can contribute too; yesterday we got over 100 hits.

OnGWT is a good aggregation of other GWT news, but it is not always kept up to date:

The official GWT blog is of course recommended:

Keeping up with the official google groups is a little more difficult, but you can occasionally find some gems:

The Lombardi guys have shipped a cool GWT app for the past several years, and are now part of IBM. 
…unfortunately I cannot find their blog at the moment; post-merge with IBM it moved.

TBroyer is getting interesting, posting in depth on new GWT 2.1 features:

There are others I follow (,, and a few others), but those above are probably the most useful.

Tuesday, September 11, 2012

Reduce the static file loading Network calls

These days we see different ways to achieve the obfuscation, minification of JavaScript code that we write in our project. This has become very important since the clients are turning fatter and fatter to stand by the WEB 2.0 standards.
Being in Java world, I was looking out for a way to achieve this in the build & deploy phase rather than doing it at runtime when the request comes for serving the content. Finally I arrived on ANT solution to do this which does both concatenating and minifying in the build phase of the project itself.

Let's start hitting the problem here with concatenating the JS files using ANT concat task
<target name="concat">
  <concat destfile="${target-folder}/<target-file-name>-concat.js" encoding="UTF-8" >
    <filelist dir="${src}" files= "<file1.js>,<file2.js>">
Above target makes sure to concat the file content present in all files mentioned in the filelist to ultimately end up in target-file.js. So as developers we just keep writing the modularized code in separate JS files and we leverage ANT to do the concatenation of all these for keeping the Network calls to minimum. 

Now the minification part comes. One reliable way I found to achieve this is YUI compressor. More than reliable, I should say standardized, efficient way of achieving the things.
Lets jump into the ANT code to see how can we get this.

First we need to show the YUI Compressor Jar to ANT environment to get the minification done on the files. So let's set a property by name compressor 
<property name="compressor"  location="${root}/yui_compressor/yuicompressor-2.4.2.jar"/>
Now lets point that location from out ANT minification target
<target name="min">    
  <apply executable="java" parallel="false" dest="${min}" taskname="yui">
    <fileset dir="${concat}">
        <include name="<file-name>-concat.js"/>
    <arg line="-jar"></arg>
    <arg path="${compressor}"></arg>
    <arg line="--charset UTF-8"/>
    <arg line="-v"></arg>
    <arg line="-o"></arg>
    <mapper type="glob" from="*-concat.js" to="*-min.js"></mapper>
Here I'm presuming the source file name has -concat.js as its suffix for the YUI mapper to convert it to -min.js after the minification task.
Bottom Line :
In addition to what I've mentioned, offers few more solutions to do the same job with out much pain. Please refer Web Utilities for more information on how to do this. 
The above operation that we have achieved using ANT targets has been achieved at the runtime by JSCSSMergeSerlvet offered by this API which can be very helpful for anybody to have a look at.

Changing the window size per underlying content

When we look out to dynamically change the window's size based on the underlying content present in the page, we typically get several solutions to fiddle with view port height / client height / window style's height but none of them work out so well when compared to jquery's way of doing the things.

It does a beautiful job of calculating the size of content and give us the exact dimensions. Lets dive deep to find out how to do it.
A note to mention here that this code works only when the native HTML popup window needs to be resized based on the content and not the parent window. (I'm not sure of it but it's almost impossible to change the dimensions of the parent window.... If I get any clue around that, I shall keep you posted on how to achieve that).

At first think of HTML page to be something like this.

Make sure to add the following style before we do the calculation for height & width.
div {
This style makes sure to constrain the DIV element to wrap only the contents present underneath it and not occupy any extra width.

Having said that, the calculation of width & height using jquery API would be really really straight forward with the following APIs.
Next comes the task of resizing the window based on the above 2 values which can be done by using the native window API i.e.
window.resizeTo (<width>, <height>);
Add-on : In addition to this, if we want the popup to be moved around automatically we can use the below API. 
window.moveTo (x,y);

External JS libraries from Google CDN

Google has provided a great way for JS developers to load the necessary third-party JS libraries from their CDN (Content Driven Networks) more easily.
As a developer, we are supposed to import one JS API file from their standard site and use the relevant API to get an advantage of this lovely CDN.

The process of doing so goes as follows
At first, import the Google JSAPI file from their repository
To make sure to call the JSAPI functions only on load of the file to the DOM, I suggest to provide a callback query param to the above network request so that we leverage the JSAPI in-built functionality of calling our API once the loading is success.

So, the typical usage of it would change to<Function Name>. Make sure the function pointing thru this function name is defined much before the network call so that the callback won't end up with no reference errors.

Secondly comes the loading of third-party libraries. This can be done in the callback mentioned before. For example if the callback function that we have given to the network call is jsAPILoaded, the call to load external libraries would be something as follows
function jsAPILoaded () {
  google.load ('<Module Name>', '<Module Version>');
Available modules that can be loaded using the a fore-mentioned API can be found here.

The next question that arises is, how would we detect the load of the external library JS file ?
Per the details given here, we can provide a callback property for which the value can either be a function name or function reference itself.
But for me, none of them worked when I tried to download jquery API using this API. So, how to detect the load of the external JS file ? JSAPI provided a way for us to register the function reference using their setOnLoadCallback function. Typical usage of this would be something like
google.setOnLoadCallback(<Function Reference>);
For example
function jsLoaded() {
   // third-party library specific code goes here
Bottom Line:
If you don't want to use JSAPI but still want to leverage the advantage of Google's CDN, Google's AJAX libraries are for you.

Third-party libraries and the target URLs that can directly be used to load them to our environment can be found here. Refer the snippet of code given at the URL and utilize the CDN way of loading the static files.

Finally hail CDN hail !!!

Tuesday, August 21, 2012



6 Websites to Search for Free e-books on the Web

A lot of free ebook sites are present out there and you can find almost any book you want online. So here is a list of 6 best ebook sites, that every book lover must check out.
You may like this : jQuery ebookebooks for developers etc

1. Ebook Search Engines
Well where do you start your ebook search from? From Ebook Search Engines of course! They are search engines similar to Google but for PDF files only. All you have to do is to type the title of the document or book name and then click the search button. Then simply look for your book in the search results and click on the download link. Voila! You have downloaded your ebook.

Best Ebook Search Engines:

Well in simple words, Scribd is the Youtube for documents. Users can upload whatever text documents they want and then share them with other users easily.
A lot of ebooks can be found here but you have to know what to look for. For example search for George OrwellLeo Tolstoi, etc.
Like Youtube has copyrighted videos, it has copyrighted ebooks, so you can find many of them on Scribd. Scribd is also a great resource for free document templates.
3. Project Gutenberg

PG boasts the biggest collection of public domain books. Many books are out of copyright and can be used for any purpose. Books from great authors like Dickens, Joyce, Shakespeare, Mark Twain, Anton Chekov and Edgar Allan Poe are in this category.

It is one of the most popular and oldest free ebooks site out there and has more than 20,000 books. Check out their Top 100 page if you don’t know where to start from.
4. Free Ebooks For Your iPod, PDA, Smartphone, Blackberry etc.
If you are one of those people who want ebooks on their portabe device, then you should definitely check out these websites:
For iPhone users: There is a site named TextOnPhne which has more than 30,000 free books and also has its own ebook reader app. Check out the demo video given here.
5. Free Tech Ebooks
If you want to get free tech books from computer science, engineering and mathematics books to programming and web development books then you should definitely check out these websites given below:
This website is a bit different. It delivers a small excerpt from the book of your choice to your email everyday, till the book finishes. It takes about 3-5 minutes to read each excerpt, and if you want to read more you can always request a next excerpt with a click of a button.

Which ebooks website do you use? Share them with us in comments.

JDK version known from a class file

Below is the list of the major to minor version identifiers used for different JDKs released so far. I shall keep this post updated as and when there is a new JDK released.

  • Java 1.2 uses major version 46
  • Java 1.3 uses major version 47
  • Java 1.4 uses major version 48
  • Java 5 uses major version 49
  • Java 6 uses major version 50
  • Java 7 uses major version 51
This info is very useful when you get a class version mismatch issue when you are trying to run a jar with incompatible JDK version. 

How to solve this when you have a different JDK version being used in your local system 

  • Download JDKs from
  • Unzip it to a proper place holder in your system (For example to C: drive)
  • Open a command prompt
  • Echo the current version i.e. being used  with "java -version" 
  • Type in the following commands to change the JDK version.
    • set JAVA_HOME=<New JDK Path>
      set path=<New JDK Path>\bin;%path%
  • Check for the JDK version for the current environment by passing the same old command "java -version"
  • You must see the changed JDK to the one that you really want to use.
Last but not least... If you want to know the JDK version used to generate a particular class file.. Use the  following command to know that.
           javap -verbose <Class Name>  (Only the Class Name with out .class extension)

Wednesday, September 14, 2011

Margin vs Padding in CSS

While being at CSS development, I always wonder the difference between margin and padding and keep asking myself a lot of questions like Which part of an HTML element would margin be affected ? If margin is something on the outer part of an element, what is padding then ? How it will impact the layout of an element on any page.

Today I have concluded myself on some basic idea by understanding the exact way it works and came out with an image (Can't think more than MS-Paint to draw this) which can easily describe how these style properties would effect an element's layout. The image I had in my mind came out something like this

Description of each property goes like this

Margin -- to separate the block from things outside it
Padding -- move the contents away from the edges of the block
Border -- Quite evident what it does

Games using JS

There has been a fantasy for me to develop some good games using JS and searching around it in the web for sometime. Intense googling would apparently allow me to find some minor stuff which was not at all reaching my expectations. 
While I was not at work, I today got sometime to google around for sometime looking for a valid resource for the frameworks / libraries using which we can develop some games that uses WebGL of the browsers and display the characters and things of the game. Finally landed on a page which allowed me to delve deeper into several libraries which are in the market for quite sometime.
Now it's my turn to use them to the full extent and develop one for myself. 

Best Practices for speeding up website

Came across a great resource to consider while building any application. It has a great set of optimization techniques mentioned which are worthwhile reading about.

Tuesday, September 6, 2011


In my last post, I have taken you people thru the important concept that went behind HDFS (Hadoop Distributed File System) a great solution for distributed computing. Now it's time to delve deeper into the details of what Hadoop is ? How it came into existence ? Does it really solve what it says ?

Thursday, August 4, 2011

Java Code to Validate Credit Card Number

May there be a case to validate the Credit card number entered by user in any Application, here is a code snippet that follows a standard way to do that at our end instead of relying on external / 3rd party libraries.

To find how can we resort on some prime information that can be helpful for us to design this API can be found @ the below links

Bank Card Numbers

List of Bank ID Numbers 

And finally the algorithm that can be backed up for doing this kind of logics would be Luhn Algorithm.

import java.util.*;
public class CreditCardValidation {
    //Credit Card Types
    public static final int INVALID = -1;
    public static final int MASTERCARD = 1;
    public static final int AMERICAN_EXPRESS = 2;
    public static final int VISA = 0;
    public static final int EN_ROUTE = 3;
    public static final int DINERS_CLUB = 4;
    private static final String [] cardNames = { "Visa" ,
        "American Express",
        "En Route",
        "Diner's CLub/Carte Blanche",
    /* Validate Credit Card number */
    public static boolean validCC(String number) throws Exception {
        int CardID;
        if ( (CardID = getCardID(number)) != -1)
        return validCCNumber(number);
        return false;
    public static int getCardID(String number) {
        int valid = INVALID;
        String digit1 = number.substring(0,1);
        String digit2 = number.substring(0,2);
        String digit3 = number.substring(0,3);
        String digit4 = number.substring(0,4);
        if (isNumber(number)) {
            /* ----
            ** VISA prefix=4
            ** if so then length=13 or 16
            if (digit1.equals("4")) {
                if (number.length() == 13 || number.length() == 16)
                valid = VISA;
            /* ----------
            ** MASTERCARD prefix= 51 ... 55
            ** and the String length= 16
            else if (digit2.compareTo("51")&gt;=0 && digit2.compareTo("55")&lt;=0) {
                if (number.length() == 16)
                valid = MASTERCARD;
            /* ----
            ** AMEX prefix=34 or 37
            ** and String length=15
            else if (digit2.equals("34") || digit2.equals("37")) {
                if (number.length() == 15)
                valid = AMERICAN_EXPRESS;
            /* -----
            ** ENROU prefix=2014 or 2149
            ** String length=15
            else if (digit4.equals("2014") || digit4.equals("2149")) {
                if (number.length() == 15)
                valid = EN_ROUTE;
            /* -----
            ** DCLUB prefix=300 ... 305 or 36 or 38
            ** and String length=14
            else if (digit2.equals("36") || digit2.equals("38") ||
            (digit3.compareTo("300")&gt;=0 && digit3.compareTo("305")&lt;=0)) {
                if (number.length() == 14)
                valid = DINERS_CLUB;
        return valid;
        /* ----
        ** DISCOVER card prefix = 60
        ** string Length = 16
        ** left as an exercise ...
    public static boolean isNumber(String n) {
        try {
            double d = Double.valueOf(n).doubleValue();
            return true;
        catch (NumberFormatException e) {
            return false;
    public static String getCardName(int id) {
        return (id &gt; -1 && id &lt; cardNames.length ? cardNames[id] : "");
    public static boolean validCCNumber(String n) {
        try {
            int j = n.length();
            String [] s1 = new String[j];
            for (int i=0; i &lt; n.length(); i++) s1[i] = "" + n.charAt(i);
            int checksum = 0;
            for (int i=s1.length-1; i &gt;= 0; i-= 2) {
                int k = 0;
                if (i &gt; 0) {
                    k = Integer.valueOf(s1[i-1]).intValue() * 2;
                    if (k &gt; 9) {
                        String s = "" + k;
                        k = Integer.valueOf(s.substring(0,1)).intValue() +
                    checksum += Integer.valueOf(s1[i]).intValue() + k;
                checksum += Integer.valueOf(s1[0]).intValue();
            return ((checksum % 10) == 0);
        catch (Exception e) {
            return false;
    public static void main(String args[]) throws Exception {
        String aCard = "";
        if (args.length &gt; 0)
        aCard = args[0];
        else {
            BufferedReader input =
            new BufferedReader(new InputStreamReader(;
            System.out.print("Enter the Card number : ");
            aCard = input.readLine();
        if (getCardID(aCard) &gt; -1) {
            System.out.println("This is a Valid Credit Card");
            System.out.println("and the Card Type is " + getCardName(getCardID(aCard)));
            System.out.println("The card number " + aCard + " is "
            + (validCC(aCard)?" good.":" bad."));
        System.out.println("Sorry this is an invalid Credit Card Number");