Road to FOSDEM 2010

As most of you already know (if you don’t, never mind, I will forgive you :D), I’m going to give a lightning talk in the Free Java Dev room at FOSDEM about Groovy. The title will be “Groovy: the cool side of java” and basically it will be an hand-on speech. No slide, just code. I will start from a simple Java code and I will rewrite it in Groovy. During the demo/live I will give some basics explanation about how is groovy working and we will see the power and the value that Groovy add at the top of JVM compared with a static language like Java.

Here the code that I wrote:

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

class TestJava{
   public static void main(String[] args) {
      new DoStuffs().doIt();
   }
}

class DoStuffs{

   public void doIt(){

   List al = new ArrayList();

   System.out.println("* Initial size of"+al.getClass()+" :  " + al.size() + " with elements "+al);

   al.add("this");
   al.add("is");
   al.add("just");
   al.add("test");

   System.out.println("* Final size of"+al.getClass()+" :  " + al.size() + " with elements "+al);
   System.out.println("* Let's add some stuffs");

   al.add(2,"a");
   al.add(3,"cool");

   System.out.println("* Done "+al);
   System.out.println("");

   System.out.println("- Before ordering"+al);
   Collections.sort(al);
   System.out.println("- After ordering "+al);
   System.out.println("");

   List al2 = al.subList(2,4);

   System.out.println("- Sublisting "+al2);
   System.out.println("");

   if(al.size() > 0){
      for (int i=0; i< al.size(); i++) {
         al.set(i, al.get(i)+" \\o/ ");
      }

      System.out.println("Let's show the element in the reverse order: ");
      for (int i=al.size()-1; i>=0; i--){
         System.out.println("<"+i+"> "+al.get(i));
      }
   }

   if(al != null){
      List sub = new ArrayList();

      for (int i=0; i< al.size(); i++) {
         String el = (String) al.get(i);
         if(el.contains("t")) {
            sub.add(al.get(i));
         }
      }
      System.out.println("- After grep "+ sub);
    }
  }
}

Leave a comment