Podcast comment

This morning I was listening to my cup of javaposse. They started a discussion about the difference between good and bad codemonkeys. The said that a good monkey would be 300% more productive than a bad one, but what’s more strange is that they would probably still be paid the same.

As I know what a lot of my collegeaus earn, I really have to agree with this. There are guys out there who really get paid way to little for what they know and do, and others who actually don’t do much get paid even more. This is really frustrating, I know that if I’m in charge of the money I’ll be giving my best programmers more than those who do little and know little.

In my former job, I now and then had to interview some sollicitants. I always asked the very simple question, tell me the difference between an abstract class and an interface. If they didn’t knew, well sorry your not a programmer in my eyes. It’s one of the basics of OO programming, what’s almost a defacto standard.

My current employer works with consultants (as I am one of them), I told him as tip. If you get a consultant, just type his name in google. If you don’t get any results, I for one wouldn’t hire them (unless he can explain). Why you might ask, well actually very simple. If you can’t find something, where do you look. Google,Support,… in most cases if you log a question or something you have to provider your credentials, so you leave your credentials behind. These things get picked up by search engines. It’s not always true off course, but in many cases it will give you an indication of the person who is sitting before you.

Now I was wondering if you could take it one step further. Afaik if you are programming you are using your keyboard, hence a person who knows who to type without looking at his keyboard should be faster than someone who needs to look at his keys. So should you say, if you can’t type, you won’t get the job, or is this taking it one step to far?

Moving

The past years I’ve been living together with 3 friends. We rented a house in Kessel-Lo (near leuven). As of today the I’m renting a small appartment, it’s on the Diestsesteenweg (behind the train station in Leuven). It’s a new appartment, this weekend we painted the bedroom and the kitchen. Still to do is the livingroom,hall,storage and my office. At first I’ll be living in it mostly alone as my girlfriend still is studying in Hasselt, she will be joining me after her studies or if she misses me to much still this year. Who knows 🙂

One of the things I hope to accomplish with living alone is to get some spare time for doing some opensource development. At the moment all of my time goes into my own company and driving to work. When everything is finished I’m willing to ‘host’ some hacking evenings for those people who are interested, I’ll mention it over here. Who knows maybe it grows to some great Belgian event 🙂

Gnome fonts follow up

It’s only been 1 day since I setup my gnome to use a smaller font, but it already feels much nicer. Really amazing what a small little change can do. I’m one of those persons who wants as much as possible on his screen. Maybe that’s something typically for coders? Many people I know want clear and big fonts, I want small and more.

For all you coders out there who use gnome and haven’t set there font smallers, really try it out. Maybe you’ll have the same reaction as me.

One thing I noticed was the fact that eclipse has it’s own font settings and I had to change these manually, no biggy but it’s a shame it’s not (yet) integrated.

gnome fonts

In my spare time I always use gnome, but during the day I have to use microsoft. (Client Company policy) One thing that was always bizarre was the fact that in my day job my computer is running at 1200×1024 and my laptop is running 1440×900. But I always had the feeling my windows maching could display more on a smaller screen. So I started looking around in my ubuntu menu’s and I found a configuration under System -> Preferences -> fonts (It was in dutch so I’m not sure if this is the actual translation but should be something like this)

I included a before and after screenshot, just like at the amount of information that is displayed on my screen now. I’m back a happy hacker 🙂

before the update
before

after the update
after

the font menu
font menu

I updated the font size and set it to 8 instead of 10, Appearantly if you change the dpi settings you can do something similar but I don’t know the exact difference between the 2 (I now what they mean but don’t know exactly what impact they have on the system.)

Generics sweetness

As I wrote earlier, last week I did a presentation on Hibernate as a good speaker I investigate my subject. During my investigation I came a cross the project that is being done for the Hibernate in Action second edition. In this book they used some generics for creating the CRUD DAO objects and it really opened my eyes. For me generics was a nice to have gadget for typecasting my collections, I had no idea this could be done with it. So read and be amazed!!

You have an interface like this:

public interface GenericDAO<T , ID extends Serializable>{
    T findById(ID id, boolean lock);
    List<T> findAll();
    List<T> findByExample(T exampleInstance, String... excludeProperty);
    T makePersistent(T entity);
    void makeTransient(T entity);
    void flush();
}


you have an basic implementation of this interface:

public abstract class GenericHibernateDAO<t , ID extends Serializable> implements GenericDAO<t , ID> {
    private Class<T> persistentClass;
    private Session session;
    public GenericHibernateDAO() {
        this.persistentClass = (Class<T>) ((ParameterizedType) getClass()
                                .getGenericSuperclass()).getActualTypeArguments()[0];
     }
    @SuppressWarnings("unchecked")
    public void setSession(Session s) {
        this.session = s;
    }
    protected Session getSession() {
        if (session == null)
            throw new IllegalStateException("Session has not been set on DAO before usage");
        return session;
    }
    public Class<T> getPersistentClass() {
        return persistentClass;
    }
    @SuppressWarnings("unchecked")
    public T findById(ID id, boolean lock) {
        T entity;
        if (lock)
            entity = (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);
        else
            entity = (T) getSession().load(getPersistentClass(), id);

        return entity;
    }
    @SuppressWarnings("unchecked")
    public List<T> findAll() {
        return findByCriteria();
    }
    @SuppressWarnings("unchecked")
    public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        Example example =  Example.create(exampleInstance);
        for (String exclude : excludeProperty) {
            example.excludeProperty(exclude);
        }
        crit.add(example);
        return crit.list();
    }
    @SuppressWarnings("unchecked")
    public T makePersistent(T entity) {
        getSession().saveOrUpdate(entity);
        return entity;
    }
    public void makeTransient(T entity) {
        getSession().delete(entity);
    }
    public void flush() {
        getSession().flush();
    }
    /**
     * Use this inside subclasses as a convenience method.
     */
    @SuppressWarnings("unchecked")
    protected List<T> findByCriteria(Criterion... criterion) {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        for (Criterion c : criterion) {
            crit.add(c);
        }
        return crit.list();
   }

}

And you have a descendent of this base class

public class BillingDetailsDAOHibernate
        extends     GenericHibernateDAO<Billingdetails , Long>
        implements  BillingDetailsDAO {

    @SuppressWarnings("unchecked")
    public List<Billingdetails> findConcrete(Class concreteClass) {
        return getSession().createCriteria(concreteClass).list();
    }
}

In short the descendent tells his parent Substitute all you T with BillingDetails and your Id with Long and abracadabra you have a simple CRUD dao for your billingDetails. Now how’s that for some fancy programming.

At the moment I’m rewritting my DAO objects to return generic collections, maybe in the next refactoring cycle I’ll use this design pattern.

My bet is that with the rise of generics, we’ll see more and more design patterns that are based on generics as this is very powerfull. The example above will surely be used in more projects to come!!

No reaction about my JUG, guess nobody is interested in learning Java. 🙁

ps sorry if wordpress f*cked up the layout, but still check it out

Jboss messaging

I had to give jboss messaging a go to. Hmm doesn’t look that difficult either. Now a simple MessageDrivenBean and I’m in business.

The Sender:

import java.util.Properties;

import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class JbossJmsTest
{

   public static void main(String[] args) throws Exception
   {
      log.info("Creating jndi context - alternatively use a jndi.properties");
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
      properties.put(Context.PROVIDER_URL, "localhost");
      InitialContext ctx = new InitialContext(properties);

      log.info("Looking up queue");
      Queue queue = (Queue) ctx.lookup("queue/testQueue");

      log.info("Looking up connection factory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");

      log.info("Creating connection");
      QueueConnection qc = qcf.createQueueConnection();
      try
      {
         log.info("Creating session");
         QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
         
         log.info("Creating sender");
         QueueSender sender = qs.createSender(queue);

         log.info("Creating message");
         TextMessage message = qs.createTextMessage("hello");

         log.info("Sending message");
         sender.send(message);
      }
      finally
      {
         qc.close();
      }
   }

   public static class log
   {
      public static void info(String message)
      {
         System.out.println(message);
      }
      public static void error(String message, Throwable t)
      {
         System.err.println(message);
         t.printStackTrace();
      }
   }
}

The receiver

import java.util.Properties;

import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class JbossJmsReceiver {
	public static void main(String[] args) throws Exception
	   {
	      log.info("Creating jndi context - alternatively use a jndi.properties");
	      Properties properties = new Properties();
	      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
	      properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
	      properties.put(Context.PROVIDER_URL, "localhost");
	      InitialContext ctx = new InitialContext(properties);

	      log.info("Looking up queue");
	      Queue queue = (Queue) ctx.lookup("queue/testQueue");

	      log.info("Looking up connection factory");
	      QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");

	      log.info("Creating connection");
	      QueueConnection qc = qcf.createQueueConnection();
	      try
	      {
	         log.info("Creating session");
	         QueueSession qs = qc.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);

	         log.info("Creating receiver");
	         QueueReceiver receiver = qs.createReceiver(queue);

	         log.info("Try to receive message, it will not work");
	         while(true){
		    	 Message received = receiver.receiveNoWait();
		    	 /*if (received != null)
		    		 throw new RuntimeException("Should not get a message if the connection is not started!");*/
		
		    	 //log.info("You have to start the connection before receiving messages");
		    	 qc.start();
		
		    	 //log.info("This receive will work");
		    	 received = receiver.receiveNoWait();
		    	 if(received!=null){
		    		 log.info("Got message: " + received);
		    	 }
	         }
	      }
	      finally
	      {
	         qc.close();
	      }
	   }

	   public static class log
	   {
	      public static void info(String message)
	      {
	         System.out.println(message);
	      }
	      public static void error(String message, Throwable t)
	      {
	         System.err.println(message);
	         t.printStackTrace();
	      }
	   }
}

this is almost the identic code of the jboss site only problem is finding it. It seems jboss has changed the jms server. I’m using jboss-4.0.3SP1 and somewhere they have changed JbossMQ to JBossMessaging or something. I still have to get the details but first things first getting some code working 🙂

First Jabber POC

On my current project I see some real future into messaging. I had some intensive discussions with my manager as he is more pro SOAP webservices then into messaging. But when you have push and pull mechanisms SOAP really isn’t the answer, what would you do? setup 2 SOAP services and let them communicate?? Well what if the specs change and a third party joins in? recode everything and if bla = true connect to X, else connect to Y? Really not!!!
What you can do is place a Queue where you publish everything on. You can use Jboss 4, it has one build in or if you want to go further you could use the Jabber protocol (same as google talk if I’m not mistaken). I have a jabber running on my server and did a very small test in java. I used the smack library, a small native java library. And I wrote this stupid little expample

public static void main(String[] args){
		try {
			XMPPConnection.DEBUG_ENABLED = true;
			SSLXMPPConnection.DEBUG_ENABLED = true;
			XMPPConnection con = new XMPPConnection("pczone.be",5222);
			con.login("xxx", "xxx");
			con.createChat("me").sendMessage("hello");
			PacketFilter filter = new PacketTypeFilter(Message.class);
			PacketCollector myCollector = con.createPacketCollector(filter);
			
			PacketListener myListener = new PacketListener(){
				public void processPacket(Packet pac){
					System.out.println(pac.toString());
				}
			};
			con.addPacketListener(myListener,filter);
		} catch (Exception e) {
			e.printStackTrace();
		}
}

What this stupid little example did was simply logon to my server, send me a message and listen for incoming messages. I ran this in debugmode with a breakpoint on the System.out.println line, when I replied to my message my breakpoint worked. I could inspect the message and see somewhere in the body my content wrapped in a jabber xml.

Off course it’s no rocket science, but it’s always nice when you see something spectaculair. 🙂

I’ll certainly use this in future projects. How exactly, hmm not yet sure 🙂

Java Workshop

Yesterday evening we did an internal workshop. I explained Hibernate a bit Jacob (a collegeau) also shared his experiences on the Hibernate topic as we implemented Hibernate in a totally different way. Afterwards Jacob gave a session on Spring Webflow. I have to say it’s been a while since I went to programmers workshop. Our l2u meetings are not actually coding, more setting up and explaing new stuff. But hey I’m a coder, not an administrator but as most geeks I know my way around administration as well but it’s not my core business 🙂

I spend quite some time preparing the workshop, I even listened to a session of gavin himself recorded on a mp3 player. (I’ll put it up later.) I made a small example and then I did a pojo with 2 relationships to other tables. While preparing this workhop it gave me the opportunity to take a closer look at the things we don’t use in our project. .e.g. we always use HQL to retrieve our objects. Never do we use the Criteria classes way, it comes down to the same thing but it’s more Object oriented then an EJBQL like query 🙂

Although Jacob his session was rather short (due to our enthousiasm) it was really interesting. I had read the spring book, but I can’t remember much from the web flow framework besides it being a continution framework. I have to say it was a lot to take at once but it’s really really nice.
As most of you might know one of the common problems in J2EE web application is that if a user starts at page A, go’s to page B, go’s to page C and then hits the back button 2 times, changes something in form A and submits it. We actually have a merge of page C with page A. This is a problem and this is where a continuation framework comes to the rescue.
It holds some kind of version of the submited paged and if you your back button a couple of times and then submit the serverside object’s state will correspond as if you had never gone any further in your workflow. You actually went back in your workflow.
He also explained that you can define flows. Let’s say you have a OrderFlow,SearchProductFlow and SearchCustomerFlow. You can start your OrderFlow and when you come to the state where the product should get added you leavy your OrderFlow and start a subflow, the SearchProductFlow. Once this flow has finished (and the user has his selected products) we return those products into the OrderFlow and we go on from the point we left it. You then go a couple of steps further and come to the point you have to select a Customer, then you start another subflow, SearchCustomerFlow,… you get the point.

I’m not quite sure, but I believe Ruby on Rails also has this feature. I bet there are more projects out there that do this, but in Java this was rather hard to do. until now offcourse

On another note I was talking to a friend of mine, I told him I was going to give a talk on Hibernate. He told me would have loved to join, but it was an internal workshop. I talked to my boss about this and kinda proposed to make a more open thing. Something like a jug. I know we have Bejug but I haven’t seen much events off them and on their site isn’t much info about them, therefor I would like to ask if any of the readers of this entry who are interested in joining such a jug would send me an email (fix dot pczone dot be). who knows if we can get a small community together we could actually do a session at least once a month. Probably in the future 1 topic per session will be done as 2 topics were really to much 🙂

So Axel or Tom who’s next 😉

evolution

Today someone told me, you always come back to money and cars, talk more about hacking would ya. Well actually I know that I talk about this a lot but there is a good reason for this. I’m 26 years old and counting, my girlfriend and I have been together for over 2 years now, next year is here last year at college. After she finishes she’ll move in with me and we’ll start saving for our own litlle house with a garden. That was the only requirement she had.
So I started counting, I have been working for over 4 years full time and during my collega I did summer jobs and after school I helped in small software firms. Building php3 applications (those were the days 🙂 ). As I’m not the big spender I do have some savings my girlfriend however (as every student) has little savings.

We agreed that in the future we would have 2 kids, and that I would get my own little office in our house. That makes a 4 bedroom house, nobody likes commuting to work but I will have to do it, that’s no problem at all but how long my commute will take is the question. Will I buy a house where they still are cheap and commute for nearly 3 hours every day or spend some more money and commute only 1 hour a day, hmm though question. But now comes the point I wanted to make, if at the moment you want to buy a small house with 4 bedrooms and a small garden, well that’s gonna cost you easily 200.000 €. Well I for one don’t have that money, so I started looking at loans. Well let’s say you leand 180.000 € (you don’t want to blow all your savings!!) well that comes down to over 1200 € a month for 20 years. Kinda makes me sad. Well blaming me about talking to much about money is the same as blaming me about thinking about my future!!! So first things first, I’ll be putting my self on the (hopefully) right track to the future my girlfriend and I want, once I’m on that track I promise I’ll be my old self again and I’ll be talking about coding day and night. And that’s a promise I’m not going to brake, So don’t worry I’m not going to become a suite. Maybe from the outside I’ll be wearing one, but hey it’s easier to influences from the inside and you musn’t judge people on how they look, right?! Yes right!!!

Istanbul

As I like everybody like screencasts, I fiddled with Istanbul. Seems it has some problems recording my desktop. My guess is, it’s because of my ati pci-express videocard that wasn’t supported when I configured my X. Congrats to the team of Istanbul, I like your product. It makes screencasting really simple, and It even records in Theorra. What could a guy want more 🙂 (hmmm, maybe sound?). In combination with java applet of the fluendo guys that really makes a kick ass combo for doing demo’s and tutorials. As the people over here are also giving demo’s and tutorials I’ll show them the nice features of the opensource applications and who knows maybe they’ll even buy support.

I really need to follow up on my videocard support, maybe by now it is supported and I can run Xgl without my X crashing after 5 minutes 🙂