Reficio™ - Reestablish your software!

Hackergarten coding session at centeractive!

I am pleased to invite you to the first Hackergarten session that will be held at centeractive (Worbstrasse 170, Guemligen) on Friday – 23rd of November!

Hackergarten is a craftmen’s workshop, classroom, a laboratory, a social circle, a writing group, a playground, and an artist’s studio. Our goal is to create something that others can use; whether it be working software, improved documentation, or better educational materials. Our intent is to end each meeting with a patch or similar contribution submitted to an open and public project. Membership is open to anyone willing to contribution their time.

Our plan is to begin at 17.30 and have a lot of fun coding together – in pairs or bigger groups – eating pizza and drinking beer right from the start :)

What will we work on?

  • Hamlet D’Arcy who is a groovy commiter, mentor and expert working at the canoo ag in Basel will join us so we’re gonna have a lot of Groovy stuff to work on during the session.
  • Tom Bujok will prepare some topics on the soap-ws project that he is the leader of, so if you want to touch the void and play with some Web-Services you simply cannot miss out on this!
  • Or we can pick up any other topic and simply work on it a bit…

Please invite your friends (developers) – everybody is invited. By the way, every participant will get a free Retrospective Log Analyzer license.

Please let me know if you come and with how many people – we have to know how many people we buy beer for :) – simply contact me on LinkedIn.

EDIT: Andres Almiray (the Griffon project lead and the Java Champion) will join us, so expect some cool Griffon stuff coming up! Thanks Andres!

Hardcore Java: Quine and Backward quine

Browsing through old university folders I found interesting pieces of code that I wrote some time ago for a contest at IBM. Have you ever heard of a quine? If not, here’s the definition by Wikipedia:

In computing, a quine is a computer program which produces a copy of its own source code as its only output. (…). For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language.

Now, when everything is clear – let’s amuse ourselves and write a shortest possibile quine in Java :)
After some experimenting, I ended up with a Java code which consisted of 135 characters (the code is wrapped for better readability):

That’s all you think? – no class, no main method? Yes, but let’s make some test in order to prove the correctness of the presented approach (note: you won’t run it in eclipse – you have to use command line) :

OK, but grouches may say that it is an old trick – and that’s actually true. You can google much stuff concerning that problem. So, let’s raise the bar and write a shortest backward quine – a program which will output its content backwardly. I haven’t found a word about it on the Internet. My version contains 191 characters:

Is your version shorter :) ? Groovy version is gonna be much briefer – I will code it and post soon…

JavaCamp #1 in Krakow

Last weekend I returned to Krakow to take part in the Java Camp meeting. I decided to travel by car, which was actually an unfortunate decision. 300km, 2 traffic jams, 6 hours of driving – all these facts perfectly summarize my journey :(   The meeting was organized by PJUG (Polish Java User Group). It took place at AGH University of Science and Technology which I have graduated from, thus it was really nice to return there. The agenda was interesting, especially when you consider the fact that I was one of the speakers :)

The meeting began with the session called “Developing Rich Web Applications in JBoss RichFaces” led by Marcin Nowrot. Marcin presented the overview of the newest RichFaces (3.3) components by showing a sample demo application. I have to admit that this session wasn’t really beneficial for me since it was more like a RichFaces advert. I expected an objective review which would summarize all the pros and cons of the library, so all in all, I was disappointed. I also didn’t like the fact that hardly no code was shown. What is more, Marcin’s application was similar to the Exadel Demo so everybody could do the same test at home. The last thing I would like to mention is the speech code used by Marcin. Addressing people by sir or madame is not a common behavior on JUG meetings – it built a wall between Marcin and the audience. But I would like to emphasize the fact that it is only my humble opinion – I am sure that there were many people that enjoyed the session.

Afterwards, I presented jBPM in action! The main goal of my session was to present the most important advantages of leveraging jBPM capabilities in an ordinary JEE application. I also wanted to popularize it a bit since in Poland it is rather unknown. It was confirmed by the fact that only two people raised their hands after I asked how many of them had used any of BPM frameworks before (there was about 60-80 people present). After outlining the basic concepts of BPM I went into the details of jBPM. I presented the wide variety of jBPM tools: ant installer, web console, eclipse plugin and signavio editor. Later, I showed two examples which explained how to integrate jBPM with EJB and Spring. In my opinion people were a little bit surprised that it can be done so easily. Yeah, jBPM is lightweight! Finally, I presented a sample business application implemented in… Grails. It was supposed to automate the process regarding JUG meeting’s organization. Some methods were implemented in two ways: with and without jBPM. First of all I showed the version which didn’t use jBPM – business rules and the logic of the process were hard-coded. Later I showed the version which was implemented with the usage of jBPM. Then I explained all the advantages and disadvantages of such approach. According to the feedback that I received my presentation wasn’t so bad but I don’t want to rate myself… :)

Later, we had the possibility to get acquainted with JavaFX. Andrzej Grzesik introduced the concept of RIA. It is the acronym of Rich Internet Application, but you can also find different kind of RIAs on the Internet :) The presentation was cool. Andrzej shared his experience concerning JavaFX giving an objective view of it’s current status and stability. JavaFX and RIA do not belong to my current area of interest, but it was cool to deepen my knowledge in that field.

Next, there was a long awaited pizza break! It was a great opportunity to chat with other developers and to exchange opinions concerning the sessions which were already held. Pizza was a little bit to spicy :D so we have drunk all the coke left to stay alive, but who cares – it was great!

The last session that I attended was the “Matlab Java Injection” presented by Miroslav Kopecky from Prague. It was a really good presentation! Mirek showed how to leverage Matlab’s capabilities directly in Java applications. He explained step-by-step how to set up the environment, write Matlab functions encompassed by “m” files, import them to Java application and finally use as Java classes. Mirek also presented a wide variety of examples which enabled us to deeply understand all the covered aspects. My favorite example was the JSP servlet showing a javascript plot generated by Matlab. I was really amazed by the fact that Matlab provides such sophisticated Java integration mechanisms. I have even promised myself to write a sample Java-Matlab application, if I will find enough time…

Summing up, it was really great to visit Krakow for the second time this autumn. I met new people, learned new things and gained a priceless practical experience as a speaker. What more could I ask for?

COOLuary 2009 – a real belter of an unconference

I spent an additional day in Cracow to participate in the third edition of COOLuary organized by Grzegorz Duda and his Developer’s World. I was really excited to take part in it, since I have heard that the idea of unconference is gaining popularity nowadays.

The unconference consisted of four panel discussions (50 minutes each). Grails, BPM, Terracotta, JMS, proxying are only some examples of topics mentioned during the sessions. What I enjoyed most was the fact that the discussions were informal and all participants had the possibility to change the topic when the conversation headed toward an unintended direction. I also liked the idea of the conference being a purely face-to-face, developer-to-developer sharing of experience – without a trace of fuzz or evangelism!

The most interesting part, however, was the hands-together session with Mark Richards. It lasted three hours and I enjoyed every single minute of it! Mark spun a yarn about some of his most interesting JEE projects and problems related to them. First of all, we discussed all pros and cons of distributed transactions (JSR-95 and compensation frameworks). It is a topic where I am currently performing R&D, so I really absorbed every aspect of the session. Later we moved onto business locks, JMS byte messaging and Web-Services.
The three hours spent with Mark was the best time I have had during JDD and COOLuary and I would even come to Cracow if it were the only session that I could attend. It was so great that I really hope to be able to take part in No Fluff Just Stuff conferences to see Mark again… If you want to see Mark in action watch this movie on InfoQ .

Java Developer’s Day 2009 in Krakow

During last weekend I had the possibility to attend the Java Developer’s Day 2009 in Krakow (link) . It was the third time that I took part in this conference (also in 2006, 2007). It was a great event with a keynote speech performed by Mark Richards – one of my idols! Not only is Mark a great speaker, but also a well-educated and experienced computer scientist, thus it was a real pleasure to attend his sessions. Generally, I attended the following ones:

  • “Pimp up your domain model with jBPM” (Tom Baeyens and Joram Barrez)
    The session was really good, however Tom and Joram have only presented the overview of features encompassed by jBPM so it wasn’t anything that could attract me. I’ve been using jBPM for almost one year right now so I would rather be interested in sophisticated usage scenarios. However, I admire Tom and Joram for the last example which outlined how to set up the whole jBPM environment in 60 seconds – it was really a great show!
  • “The Art of Messaging” (keynote, Mark Richards)
    What a session it was! Mark presented a large part of knowledge regarding messaging and JMS in particular. I especially liked the results of the benchmarks performed in different messaging scenarios. The jokes were also great. I hope to see Mark back in Poland soon…
  • “Exception Handling in the Systems Built with JEE” (Tomasz Skutnik)
    Session was really interesting, however the speaker delivered some controversial statements regarding checked exceptions with which I could not agree. Tomasz also encouraged us to implement proprietary code for proper resource management. It is really concerning since these features are already implemented in frameworks such as Spring – so I encourage him to get acquainted with that…
  • “Asynchronous, Concurrent and Distributed Processing in Java EE…” (Waldemar Kot)
    The session was good. Earlier, I have never heard about the CommonJ Work Manager API – the “de facto” standard of manual thread management in JEE. One thing that annoyed me a little bit was fact that Waldi kept his hands in pockets almost all the time during the speech – in my opinion it was inappropriate. However, from the technical point of view the session was cool.
  • “Effective Code Review for Agile Java Developers” (Wojciech Seliga)
    Great presentation of the Atlassian and JetBrains products performed by a guy who was experienced in TDD and Agile. Code reviews and pair-programming were the focal points of this talk. It is really sad that I can’t see a way to use these methodologies in my company in the forthcoming decade…
  • “Common Anti-patterns and Ways to Avoid Them (Mark Richards)”
    Interesting session during which Mark presented some most popular anti-patterns. Excellent speech!
  • “The Architecture of Applications Based on DDD that use Seam and Flex” (Slawomir Sobotka)
    I had been checking my emails during this session, so I can say nothing about it… I was also pretty tired at that time.
  • “Resource-Oriented Architecture (ROA) and REST” (Scott Davis)
    Scott is a real Groovy&Grails enthusiast and it was noticeable from the very first seconds of his talk. Groovy examples were great – especially that one regarding REST service invocation implemented in one line. From the technical point of view this session was quite poor, as Scott presented a lot of evangelism. However, considering the fact that it was the last session, it was a great finish of the conference. I wasn’t disappointed…

To sum up. JDD09 was a great event! After the conference I had the possibility to meet my friends from studies – with whom I (after)partied in Jazz Rock! See you all next year!

Splitting and Tokenizing Strings in Java

There are at least two ways of tokenizing Strings in Java. Simple examples work like a charm, but it is very easy to encounter some weird or unintuitive behavior while experimenting with complex regexes or some corner cases. Thus, in order to gain deeper knowledge, I am gonna dive into the implementations details and present some general rules of string tokenizing in Java.

How to tokenize a String:

To pass for example SCJP a programmer has to predict the exact result of the split method invocation (including the empty matches – what causes most of the problems). I will now present general rules which could probably help in systematizing the knowledge regarding the String tokenization.

The rules are organized in such a way, that the preceding rules have a bigger priority that the following rules, so you should follow the list until one of the rules matches the situation you are actually examining:

1.) If the regex expression does not match any part of the input:

  • Matcher: returns exactly one element – namely the given String
  • Scanner: returns exactly one element – namely the given String

Example:

  • Matcher: “James Bond”.split(“MI6″, 0) == ["James Bond"]
  • Scanner: new Scanner(“James Bond”).useDelimiter(“MI6″).next() == “James Bond”;

2.) When the given String is empty:

  • Matcher: returns exactly one empty match [""]
  • Scanner: the result is empty []

Example:

  • Matcher: “”.split(“MI6″, 0) = [""]
  • Scanner: new Scanner(“”).useDelimiter(“MI6″).hasNext() == false;

3.) When the delimiter regex is empty:

  • Matcher (index == 0): Tokenized characters of the given String preceded by one empty String
  • Matcher (index < 0): Tokenized characters of the given String preceded and followed by one empty String
  • Scanner: Tokenized characters of the given String

Example:

  • Matcher (index == 0): “007″.split(“”, 0) = ["", "0", "0", "7"]
  • Matcher (index < 0): "007".split("", -1) = ["", "0", "0", "7", ""]
  • Scanner: Scanner s = new Scanner(“”).useDelimiter(“MI6″); s.next() = “0″, s.next() = “0″, s.next() = “7″, s.hasNext() = false;

The last thing I want to mention are the “empty-matches” or “zero-length” matches:

  • Matcher (index == 0): Returns: leading and inner “empty-matches” – BUT IF ALL MATCHES ARE EMPTY – the result set is empty
  • Matcher (index < 0): Returns: leading, inner and trailing "empty-matches"
  • Scanner: Returns: only inner “empty-matches”

Example:

  • Matcher (index == 0): “::”.split(“:”, 0) = []
  • Matcher (index < 0): "::".split(":", -1) = ["", "", ""]
  • Matcher (index == 0): “:1::2::”.split(“:”, 0) = ["" , "1", "", "2"]
  • Matcher (index < 0): ":1::2::".split(":", -1) = ["" , "1", "", "2", "", ""]
  • Scanner: Scanner s = new Scanner(“::”).useDelimiter(“:”); s.next() = “”, s.hasNext() = false;

Hope this helps!

String literal pool and JLS rules for String objects

I have been playing with the String objects in order to review all the rules defined by the JLS regarding the String creation and handling. I have recently created a JUnit test case which examines all the aforementioned rules. Enjoy!

JLS rules for Strings:

  • Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1).
  • Literal strings within different classes in the same package represent references to the same String object.
  • Literal strings within different classes in different packages likewise represent references to the same String object.
  • Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals.
  • Strings computed by concatenation at run time are newly created and therefore distinct.

Other rules:

  • Strings from the string pool are not eligible for garbage-collection since JVM maintains a single reference to each unique String object from the String pool (Subject of discussion: LINK)
  • new operator does not put newly created string into the string pool
  • From the javadoc: “String.intern() returns a canonical representation for the string object. When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.

All test methods are presented below. The code compiles and runs without errors.