Update after a long time..

Much time has passed since I write my last post. lots of  important things happened since I  had written my last last post, most important of those is moving to new organization and new city after a long time. I had some doubts and fear before moving to AKQA, but now I feel like its worth moving to new younger company.

Another thing, is to learn new stuff, CQ or(AEM) and whole lot of new technical movement that is  happening around in DevOps  (Chef, puppet) Microservices, which is the driving factor around all..

Here I found one interesting video about Microservices

Last but not least and most important

<

Advertisements

New Work

My friends has started a new site

Node Internationalizatio(I18N) approach

While searching for some work on I18N implementation approach on Node, I came across following three approach.

  • User library, example i18Next library. Example
  • Using html/javascript translation with html 5 data- attributes. Example. Here top language header is added dynamically. And translation is done using javascript node value manipulation.
  • Using different subdomain. Example

    .

  • ArrayList for loop puzzle

    Let me start this entry by asking a question. What would be the output of following two programs?
    Program1:-

    import java.util.*;
    public class ClassA{
            public static void main(String args[]){
             List<String> list = new ArrayList<String>();
             list.add("1");
             list.add("2");
             for(String x: list){
              list.remove("1");
             }
            System.out.println(list);
       }
    }
    

    Program2:

    import java.util.*;
    public class ClassA{
            public static void main(String args[]){
             List<String> list = new ArrayList<String>();
                             list.add("1");
             list.add("2");
             list.add("3");
            for(String x: list){
              list.remove("1");
             }
            System.out.println(list);
    }
    }
    

    Output:

    Program 1:

    [2]


    Program 2:-

    Exception in thread "main" java.util.ConcurrentModificationException
            at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
            at java.util.AbstractList$Itr.next(AbstractList.java:343)
            at ClassA.main(ClassA.java:8)
    

    Description:-

    Program 1 will run without any issue and delete “1” from the list and hence the output will print list content with having one element “2”. Whereas program 2 throws ConcurrentModificationException.
    Why?
    Here is the explanation.
    Java for each loop internally uses Iterable and Iterator to loop through each element of the collection. When we are looping through the foreach loop, we implicitly call list.iterator(), list.hasNext() and list.next() methods. In case of ArrayList list.iterator() returns instance of ArrayList.Itr class. This instance has a expectedModCount varable which keep track of current state of list. We can assume it to be the stamp of current state of the list. Whenever we modify the list(add/update/delete element) this modCount variable gets changes. When AbstractList.Itr is instantiated it initialized expectedModCount with current modCount of the list.(Fir understanding purpose we can say that Itr has variable which keep track of current state of the underlying list.
    When we delete an element modCount is increased and when next time itr.next() is called Itr.next() matches the mod count and throws ConcurrentModificationException if it does not match.

    The whole idea is to stop someone from modifying the underlying collection once we get Iterator and working on it.

    Then comes last question? Why no error was throws in case of Program1. It is because there are no element to be loop over and no Itr.next() method is called and hence no ConcurrentModificationException.

    Itr.remove() keeps the consistency and reassign expectedModCount.

    ArrayList source code:- http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/ArrayList.java

    atan2 function problem in db2,java,javascript

    Last day I was working on a formula to calculate the bearing(and finally direction from point 1 to point 2). I was using the formula described here. I was running same formula in java as well as DB2. But getting different result. After much analysis I found the problem with the atan2 API in DB2 and Java.

    Java API accept y and x as first and second argument where as DB2 API accepts in reverse order.  I also found that  java script also accept y argument first. This is quite bad. I don’t know which one is right but everyone should follow same pattern. This difference in API was the source of the bug.

    During this analysis I also found that Db2 client(squirrel) was not returning the precise value where as Db2 client was returning. sqirrel_db2

     

    2013 in review

    The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

    Here’s an excerpt:

    The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 20,000 times in 2013. If it were a concert at Sydney Opera House, it would take about 7 sold-out performances for that many people to see it.

    Click here to see the complete report.

    A random good thought

    Our life is possible only because we have faith on the machines around us. Just imagine the situation what life would have been if we don’t have faith on any machine around us. “The idea to develop a faithful machine/program” is the statement that always keeps me motivating. A program on which people have faith. People can have blind faith. A program on which many life can faithfully depend. I want to reach that level of perfection. Like all our perfect machines around us…like Airplanes, Train… etc…