Skip to main content

JTheque Core 2.1.0 released !

It's my pleasure to announce that I've finally released JTheque Core 2.1.0 !

The different services of the core are now separated using OSGi. With this separation, I've improved a lot the design of the core and the orthogonality of the different services. Each service is now an OSGi bundle. I've also refactored the implementation of all services. Several services have been completely rewritten. The majority of the bundles are now thread-safe.

Now, to create modules for a JTheque application, you have to write an OSGi bundle representing the module. Then, you only have to use Spring to launch the module. This is done using Spring Dynamic Modules. The used OSGi container is Felix.

Now that this version of the core is finalized, I'll updates the applications. First of all, JTheque Movies with the new version of the core.

Fore more informations and to download JTheque Core, you can go on the description page. If you want to try developing a module (or see how it is done), you can consult this starter guide.


Compute command-line arguments with Apache Commons CLI

For a project at school, I needed to refactor an old code parsing almost 30 command line arguments. I needed to add some more arguments and change some old args, but the old code was not maintainable at all. So I decided to use a library to make the parsing. of the args.

I chose Apache Commons CLI. This is a really simple library to make that parsing. It's not perfect, but it makes the work I needed and is powerful to do that job.

With this API, you have to declare an Options instance. This class is used to describe the command line arguments of the program. Options constructor don't take any arguments.

Options options = new Options();

Read more…


The Pragmatic Programmer - Book Review

This week, I finished a new book : The Pragmatic Programmer, from journeyman to master, written by Andrew Hunt and David Thomas.

According to the author, reading this book will make you a better programmer, a pragmatic programmer. A pragmatic programmer is a person who loves its work and who always want to improve it. He wants to improve its skills and to learn new technologies. He doesn't only code, he wants to provide better and better code.

This book don't focus on any language, it can be useful to programmer of every language.

I don't advice this book to complete beginners because this book contains a lot of different ideas that can discourage neophyte because of the lot of works they must provide to become a real pragmatic programmer.

You will learn several very important things in these books :

  • Have a pragmatic philosophy : Assume your responsibilities, don't let broken windows appears, fix issues as they come, make quality software, improve your knowledges, communicate with other persons, ...
  • Adopt a pragmatic approach : Duplication is Hell, Orthogonality is Heaven, use tracer bullets and prototype when starting projects to achieve your objectives
  • Use the good tools : Use good editors, automate all that you can, construct a set of tools for your usage
  • Be paranoiac : design by contract, use exceptions, ...
  • Don't go to deep in your errors
  • Make your code better and better while you're coding, consider the speed of algorithms
  • Before the project, get the good requirements, specify as good as you can
  • Create a pragmatic team

Like you can see this book provide a long list of advices, that is not always easy to read and to understand. I've made a lot of pauses, re-reading a passage to have a good understanding of the whole lot.

I''ve found all the advices very good and interesting and I think that applying these advices will help me to make better work.

But, I must say that some chapters have not aged well. Especially, on tools. The authors advice to use only tools like plain text editor and shell commands. I think that with the power of modern IDE we can save a lot of time.

But this little default expected, this book is a great book, a must read book, that every programmer should read once in its life.

More informations on the website of the book :


Swing tip : A better SwingWorker without exception swallowing

When we develop Swing applications, SwingWorker are very helpful. But there is a big disadvantage using this class. if you don't call get() in the done method, you will lose all the exceptions that the computation in the doInBackground() has thrown. And you action can stop and you will never see why. In 95% of my actions using SwingWorker, the doInBackground() return nothing.

Jonathan Giles has presented on his blog a good solution to solve this exception swallowing. In my side, I've often something to do in the EDT before the doInBackground() run, so I've made the changes on the code presented by Jonathan and it gave me that simple class that I found better than the SwingWorker :

public abstract class BetterSwingWorker {
    private final SwingWorker<Void, Void> worker = new SimpleSwingWorker();

    public void execute() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {


    protected void before() {
        //Nothing by default

    protected abstract void doInBackground() throws Exception;

    protected abstract void done();

    private class SimpleSwingWorker extends SwingWorker<Void, Void> {
        protected Void doInBackground() throws Exception {

            return null;

        protected void done() {
            try {
            } catch (final InterruptedException ex) {
                throw new RuntimeException(ex);
            } catch (final ExecutionException ex) {
                throw new RuntimeException(ex.getCause());


You can use it as the default SwingWorker. You must implement the doInBackground() and done() methods and you can, only if you want, override the before() method that is invoked in the EDT at the start of the process. And then, you can execute your SwingWorker using execute().

I hope this little class can be useful to somebody.

Source for the non-swallowing swingworker.


Solve Einstein’s Riddle using Prolog

This week, we started learning Prolog at school. So to exercise, I choose the Einstein's Riddle. Einstein wrote this riddle in the 19th century. He stated that only 2% of the population can solve it by mind. Personnally, I'm not of this two %, I needed paper and pens to solve it. But this is not the them of the post, so let's use Prolog to solve it. I will present my solution, there is certainly other solutions, and certainly better, but it makes only some days that I started learning this language and this new kind of developing, logical programming.

Here is the riddle as stated by Einstein :

  1. In a street there are five houses, painted five different colours.
  2. In each house lives a person of different nationality
  3. These five homeowners each drink a different kind of beverage, smoke different brand of cigar and keep a different pet.

The question is : Who owns the fish ?

And there are 15 hints :

  1. The Brit lives in a red house.
  2. The Swede keeps dogs as pets.
  3. The Dane drinks tea.
  4. The Green house is next to, and on the left of the White house.
  5. The owner of the Green house drinks coffee.
  6. The person who smokes Pall Mall rears birds.
  7. The owner of the Yellow house smokes Dunhill.
  8. The man living in the centre house drinks milk.
  9. The Norwegian lives in the first house.
  10. The man who smokes Blends lives next to the one who keeps cats.
  11. The man who keeps horses lives next to the man who smokes Dunhill.
  12. The man who smokes Blue Master drinks beer.
  13. The German smokes Prince.
  14. The Norwegian lives next to the blue house.
  15. The man who smokes Blends has a neighbour who drinks water.

So let's start with the code !

Read more…


JDK 7 Features updated ! Plan B has apparently been approved

I was presenting the Plan B of JDK 7 the last week and apparently, this plan has been approved.

The JDK 7 Features page has been updated on the site of Oracle.

So here are the (definitive ?) list of features for JDK 7 :

  • JSR 292: Support for dynamically-typed languages (InvokeDynamic)
  • Languages update of the project Coin
  • Concurrency and collections updates (jsr166y)
  • ionet JSR 203: More new I/O APIs for the Java platform (NIO.2)
  • SCTP (Stream Control Transmission Protocol)
  • SDP (Sockets Direct Protocol)
  • Elliptic-curve cryptography (ECC)
  • client XRender pipeline for Java 2D
  • Create new platform APIs for 6u10 graphics features
  • Nimbus look-and-feel for Swing
  • Swing JLayer component

And we can also see that there is some new features that we doesn't have seen before:

  • TLS 1.2
  • JDBC 4.1
  • Unicode 6.0
  • Locale enhancement
  • Separate user locale and user-interface locale
  • NIO.2 filesystem provider for zip/jar archives
  • Use the Windows Vista IPv6 stack when available

And after all that informations, we can see the features delayed to JDK 8 :

  • JSR 294: Language and VM support for modular programming
  • JSR 308: Annotations on Java types
  • JSR TBD: Language support for collections [NEW]
  • JSR TBD: Project Lambda
  • Modularization (Project Jigsaw)
  • JSR 296: Swing application framework
  • Swing JDatePicker component

For more informations and the complete list of features for the two versions of JDK, you can consult the JDK 7 Features page. There will certainly be some additional informations at JavaOne this week.


JTheque Utils 1.1.5

It's my pleasure to announce the release of a new version of JTheque Utils, the 1.1.5.

There is a lot of changes in this version. First of all, the library is now OSGi Ready, you can use it with no problem in an OSGi application. Here are the main changes of this version :

  • The main classes have been made thread safe and all the classes are now documented to indicate if they are thread safe, not thread safe or immutable.
  • The library has now some annotations to document thread safety, thanks to Brian Goetz for the idea
  • SwingUtils support now headless environment
  • Version has a better version comparison
  • A new simple way to manage system properties with the SystemProperty class
  • CollectionUtils has a new set of methods to create collections and concurrent collections
  • A simple thread safe weak event listener list, WeakEventListenerList
  • HashCodeUtils has been improved to manage arrays
  • Some classes have been made Immutable
  • The utility class have new methods
  • And a lot of other little changes and bug fixes

More informations on the JTheque website.  You can download it from here.

I hope that this library will be useful to someone.


Java Concurrency - Part 7 : Executors and thread pools

Let's start with a new post in the Java concurrency series.

This time we'll learn how to start cleanly new threads and to manage thread pools. In Java, if you have a Runnable like this :

Runnable runnable = new Runnable(){
   public void run(){

You can easily run it in a new thread :

new Thread(runnable).start();

This is very simple and clean, but what if you've several long running tasks that you want to load in parralel and then wait for the completion of all the tasks, it's a little bit harder to code and if you want to get the return value of all the tasks it becomes really difficult to keep a good code. But like for almost any problems, Java has a solution for you, the Executors. This simple class allows you to create thread pools and thread factories.

Read more…


Hardware Guide : The power supply

After writing a lot about Java concurrency, I wanted to write about something else, I chosen Hardware, so I wrote a new guide about power supplies.


The power supply provide electrical power to the computer and to the several components. Without power supply, a computer cannot start. The power supply is connected to the power distribution system of your home and convert this power into the good number of watts needed by the components of your PC. All the power is redistributed using several different connectors.

When we buy a power supply, you need to keep in mind several elements, the available connectors and the power generated by the power supply.

Read more…


Java 7 Delays and Plan B

Mark Reinhold has posted a message about the planning of Java 7. In this message, he explains that the current schedule of the JDK 7 is completely unrealistic. This delay is due to the add of new projects (lambda, Coin, Jigsaw) and the acquisition of Sun by Oracle.

The current estimate by the team is that the JDK7 can be complete for a release around the middle of 2012.

But, Mark indicates a new option, the "Plan B". With this plan, the JDK7 will be available at mid 2011 without Jigsaw and Lambda and with only a portion of the Coin Project. And JDK8 will be released in late 2012 with the complete set of features scheduled actually for JDK7.

Personnally, I think it's a good idea to separate the two releases and have a first release soon. Like Mark says, it makes a very long time that we don't have had a new Java release, so it will be interesting to have a light JDK7 before 2012.

And you, what do you think ?

Source : Re-thinking JDK7, by Mark Reinhold