Sunday, 27 January 2013

Chapter 4 – Evolve through the versions

I think we have reached the point for writing a quick post about the versioning control and how we are going to manage it here. That will be helpful as well for sharing with you all the samples that are going to be created on this blog.

First thing to do will be to choose what our version control system will be. There are several choices available, Subversion or SVN (centralized solution into a single repository), GIT, Mercurial (distributed solutions)…

And the winner is… SVN. Why? Just because it’s the one I’m used to it.

Besides that, we’ll rely on Google Code as the central server and repository for hosting our project and share the code with you. Google offers that possibility provided that our project is Open Source Licensed.

Google code supports SVN control system in its repository and it will offer as well, apart from the hosting, review tools, issue tracker and project wiki in case it’s needed.

As we are working with Eclipse, we’ll need to install a plugging which connects us to the SVN repository. We’ll use Eclipse’s “Subversive” plugging that can be found in the following link along with the installation instructions:

The installation is really easy, just go to Eclipse, click on “Help”, then on “Install new software” menu, the type the URL shown in the image below and expand the “collaboration”. You will find in there the different connectors for GIT, SVN…

Now, select the “Subversive SVN Team provider” and click “Next” until the new software is installed. You will need to restart eclipse for applying the changes. We will be prompted to choose the connectors to install. We’ll choose latest SVN Kit library.

Ok, we are almost done. In order to access now to the public repository you just need to open the new SVN repository perspective from “Window”->”Open perspective”->”Other”.

If we click on “New repository location” and enter the following URL:

You’ll have access to the different revisions of the code that we’ll be sharing through these posts, you just need to right click on the project’s name and select “check out” option.

If you surf the Google’s Code site and look up Taikonaut project you will be able to access and download the code as well from the following link:

Well, now that last but not least thing to do is to feed up the repository with many examples that I hope they will be useful. But that will be along with the next chapters.

Bye from the wide and dark space!

Friday, 18 January 2013

Chapter 3 – Let’s log some stuff

Today I’d like to talk about a simple way of building and important component that an application usually requires. I'm talking about logging.

Sometimes, it could be needed to prepare our system for catching traces in case it’s decided to active them for just giving a deeper view of what’s happening inside.

This mechanism can be used with different level of server traces which allow us for example to have a closer look in a development environment (debug traces) or just activate the traces for really annoying problems (fatal traces) in live environment.

How can we easily achieve this without coding our own logging module? We are going to use a wide known Apache framework. I’m talking about Apache Log4J API.

The API can be downloaded from this link:

We’ll be working with version apache-log4j-1.2.17 which seems to be the last stable version at the moment. (Although there is a beta 2.x version available).

Once we get the folder of the chosen distribution, the installation is so quick as it’s just a JAR file what you need to add to your application classpath.

This simple jar contains the full bunch of classes which conforms Apache log4j API. The can be using now by importing the required classes to ours.

Let’s prepare our application for logging some different traces with different level of criticism.

In order to do that we are going to create a Main class in our project.

As you can see we have included two classes:

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

The first one contains the basis functionality we need for start logging, but before that, it will be needed to set some configuration. This configuration will be loaded with the assistance of the second class, PropertyConfigurator.

The configuration file is usually named and it can be located into a folder of our project as you can see in the previous project structure image.

Our configuration file will have a simple composition as follows:

In this file it’s possible to define as much loggers as it is required. The trace level and the name of the logger are specified when a logger is defined.

The trace level in this case is INFO, which is the lowest critical level. It means that all traces: info, warn, debug, error and fatal will be written.

Afterwards the result log file is described through the “appender” properties as well as the pattern to be used in the resulting lines of the file. Each wildcard has a different meaning that can be found in the documentation of the API in this link:

Once log4j is configured the only remaining task will be to create our log object and use the different levels of logging it provides to us as it’s explained in Main class code.

Just for showing how it’s called from a different class, we are going to create Test class which will be used from Main.

After this quick introduction, let’s execute it and see what happens.

The default output is the System.out which shows us the following messages that where included in Main class in order to known when the process starts and when it finishes.

Taikonaut project: Ignition!
Ready for landing!
Trip time:
68 milliseconds
0 seconds

It’s been a really quick journey! Well, as you can see in the image with the project structure, the result of the journey is that a log file has been created in the specified folder with the following content:

2013-01-18 19:37:01 org.taikonaut.Main : Info
2013-01-18 19:37:01 org.taikonaut.Main : warn
2013-01-18 19:37:01 org.taikonaut.Main : error
2013-01-18 19:37:01 org.taikonaut.Main : fatal
2013-01-18 19:37:01 org.taikonaut.test.Test : test info

VoilĂ ! Here it is!

Obviously log4j API has got much more functionality and you will be able to get the best of it with patient, reading documentation and practicing but I was just trying to get a brief introduction that you can use as a starting point.

Talk to you in the next chapter. Bye from the wide and dark space!

Sunday, 18 November 2012

Chapter 2 – Some documentation is not too bad

Before we start coding any line we are going to prepare our project to generate some automatic documentation that will be useful for future developers involved in the project.

In many real life projects, documentation is usually poor and people are not willing to do that task because the thoughts about the “losing time” and “hard and tedious work”.

Javadoc tool is an easy and fast way of providing a minimum documentation. You can get an HTML description of the whole API you are building in your project, with the description of classes, attributes, methods, etc…

Eclipse IDE (as well as the rest of IDEs) provides an easy way of automating this task.

First thing to when you want to do when you want to automate the documentation process is to click on “Window->Preferences->Java->Code Style->Code Templates”

The different options can be selected for its edition if desired.

Multiple lines can be added as well as variables that can be inserted as date, user, tags…

Once documentation templates are configured they will be applied as we create new classes or adding new methods to our project.

If comment needs to be created we can do it by writing /** symbol and pressing intro. This will be interpreted by javadoc as documentation to be added to the html.

Finally, in order to create the documentation, there is only one step left. We will select next menu option: “Project->Generate Javadoc”

By selecting the javadoc command at bin folder of our JDK package and clicking finish we’ll have immediately our project’s API documentation generated in HTML format in our doc folder.

Well. Now, Elvis would say: “A little less documentation a little more action”. In the next chapter.

Saturday, 10 November 2012

Chapter 1 - Getting started

The first thing we’ll do is to choose and install the tools that will be used for the development. This first entry of the blog will be focused on it. We’ll always try to build our exercises and examples based on open source technologies and tools so they can be easily available for anyone with an internet connection.

First exercises will be focused on Java technologies and therefore we’ll have to prepare our computer downloading the following components from web.

1.- The JDK (Java Development Kit) – This can be downloaded from Oracle web page. We’ll be using 1.6 release.

2.- The next step will be to choose our Integrated Development Environment (IDE) which will help and speed the coding up. We’ll install the last release of Eclipse IDE (Juno).

You can take that one from Eclipse site.

There are other important IDEs that can be used for our pourposes like Netbeans (, IntelliJ IDEA (… but we’ll be focused in Eclipse at the moment.

3.- Next thing we’ll be doing is to get a relational database management system (RDBM). The database we’ll get is Postgresql.

We can download it at Postgresql download

Again, there are other open source relational database systems as MySQL. We’ll have the opportunity to going into this topic.

In order to be able of easily and graphically managing the database we’ll download as well Pgadmin tool.

It can be downloaded at Pgadmin download

Well, once everything is properly installed we are ready for starting our engines and taking off. But, that will be in the next chapter.