April 5th, 2010

Ivan St. Ivanov

This week I am one day late (again). The reason for that is that we are having the Easter holidays. So, Христос Воскресе as we say in my country (which literally means Christ has resurrected! and is a standard greeting during the Easter days in Bulgaria).

Today I’m trying to not only present you the interesting articles from last week, but also give you my personal opinion on the topics that they discuss. I hope you’ll give yours either in our forum or directly below the article that I comment.

The basics of SQL joins

This is a article that is for all the developers (no matter Java or not) that have finally hit the database. Databases are the preferred way to store data in next to simple applications. And if you application is even a little bit more complex and you are a good software designer, you will need to put your data in more than one table. Not only that, but some of the queries that you will make will retrieve data from more than one table at a time.

So, this is where the table joins come into play. If you are new to this area, then this is the article for you. I must confess that I don’t use joins too much in my development. Even before the days of JPA I used complex select statements (from more than one table). If you are like me, then probably the outer and self joins sections will be of interest to you :-)

SQL phobia – fear of SQL

While we are still on the SQL wave, here is a very interesting article for other group of people like me – those who are going to the numerous frameworks like JPA, JDO, Hibernate, etc. that abstract writing SQL. These frameworks give you the opportunities to write XML, customize annotations and do whatever kind of magic to come over the impedance mismatch between relational databases and object oriented software. And thus escape from SQL.

The author speculates about the reasons why we started our irrational (according to him) hate to SQL. I agree with him that the hate to SQL is irrational – people should know SQL no matter of the frameworks that are created now and then. I am great fan of JPA, but I heavily use SQL in my test cases or for debug reasons. As the author mentions – SQL is not complex at all, so you should not be afraid of it.

The NoSQL “movement”, which is so popular these days, has nothing to do with SQL as a language, but rather with the relational databases. This is also mentioned by the author.

If you like to read a not so technical, but more philosophic point of view on the topic, then go on reading this blog post.

JAX-WS hello world

Here is a five minute tutorial on how to create a JAX-WS web service and a client for it. Of course as a five-minuter it is not a sophisticated CRM application for example, but rather a “Hello world” one. Anyway, it is a very good one for those of you who want to learn the basic web service interfaces and their usage in the JAX-WS flavor.

By the way, InfoQ, that has a great focus on both flavors – JAX-WS and JAX-RS, has a short blog on REST and SOAP: When Should I Use Each (or Both)?.

Soft skills article of the week

In this article you can find 9 reasons why [some of the] smart people are not able to find the greatest place to show their talents. I would encourage you to go and read the article by yourself. And then read the comments. And then possibly write a comment. But please do it only after you read my comment in the next paragraph.

In my opinion the best friend and enemy of a software developer (hopefully a smart one) is the humiliation. If you have it in a reasonable quantity, then it’s OK. What do I mean by reasonable quantity? Well, for example don’t expect that after you write your first ‘Hello world’ application in a fancy language or framework that your fellow colleagues haven’t heard about, you are the world’s expert in this matter. On the other side, don’t be too humiliated if you want to be successful. Feel free to express your opinion and be sure that by mentioning that it is your personal thought on the matter, you will not make anyone special confront with you. And even if there are people that can tell you that you are stupid, you must be sure that their statement was more stupid than you.

So, try to keep to the humiliation boundary, learn from the other people’s ideas and mistakes and you’ll be a smart guy with at least moderate success :-)

April fools’ article of the week

This week we had the April fools’ day. And the most interesting article was that Apache Software Foundation has sold all its intellectual properties and assets to Oracle for 1.5 billion dollars in cache. Well, I hope this is really an April fools article, but who knows… :-)

March 28th, 2010

by Ivan St. Ivanov

Hello Facelets, goodbye JSP

JavaServer Faces (or JSF) 2.0 is the preferred view technology in Java EE 6. Not only it lets you build rich UIs using various technologies (like AJAX for example), but you can also easily build reusable and composite view components. Although the JavaServer Pages (JSP) is still supported by the specification, JSF as of its 2.0 version will officially use the Facelets technology for the view description.

Facelets uses the same known tag libraries (JSTL core, JSTL functions, JSF core and JSF HTML) and on top it adds the JSF facelets library. It mainly contains tags for component definition and composition. Thus you can once create a login form component for example, put it in a JSF file (with extension xhtml) and then embed it in other JSF files and pages.

The above article is another good introduction to the JSF technology and the Facelets. The good news in the JSF area is that the books about version 2.0 are already coming. Ed Burns’s JavaServer Faces 2.0, The Complete Reference can already be bought. And in a month Core JavaServer Faces 3rd edition is coming. So if you want to give JSF a chance, at least read all the introductory articles like this one. :-)

Bean validation and JSR 303

One of the tasks of most of the web (and not only) applications is validating user input. Especially when the user enters some data in a form, it has to be checked whether it conforms to pre-defined rules. Sometimes the field should not be empty, other times it should be a number. Of course the business logic of the application can define very complex rules about the object attributes and the corresponding fields of the input forms.

As you can read from the article, back in the time there were two major validation frameworks: Apache Commons Validator and the Action forms validator in Struts. The third player in the game is Hibernate. Its validator framework called Hibernate Validator is now the reference implementation of the bean validation JSR. In a nutshell, you just annotate your model classes with validation rules. Then in the business layer you just call the validator API to check whether all the rules are applied with the objects coming after the user input. This helps implementing the validation logic only once and not in every layer of the application. Easy and straightforward :-)

Performance monitoring with Hibernate

The database performance is very important for the overall application efficiency. This article presents a special API from Hibernate that analyzes exactly that. Hibernate Statistics gives us valuable information about such things as number of executed queries, open transactions, loaded entities, etc.

The author of the article gives us a hint how this statistics can be used to monitor some common performance problems. You can also see how you can deploy your code as a Java EE library and use it seamlessly during your application’s runtime.

JavaFX digital clock

And now something for the JavaFX fans. This is the emerging Java visual technology with its own language (JavaFX script). With its help you can do compelling graphics and animation without writing the tons of code, inner classes, getters and setters required by Swing.

This article is very useful in that it is a step-by-step example of creating a real world (though simple) application. The author walks you through all the way from creating the project in NetBeans to running the application. Although declared as requiring intermediate skill level, it can be a perfect start even for those of you, who (like me) have only heard about the basic terms and benefits of JavaFX.

Soft skills article of the week

Most of the readers of this blog have at least once gone to a job interview. In most of the cases the employee candidates are usually the ones that answer the questions. The only thing that they really ask is the amount of the salary.

Not that it is not important, but according to the author of this short blog post, there are at least 10 questions that you should ask your future boss on the job interview. If you have some experience in this area, you can post your ideas as comments.

March 21st, 2010

by Ivan St. Ivanov

Is Java EE 6 too complicated?

The people who back and evangelize Java EE 6 are very active the last few weeks. The blogosphere is full of posts, articles and webcasts on how easy it is now to develop with Java EE 6. The reason for that I guess is that most of the people still think that Java is too slow to run and Java EE is too horrible and complex to develop.

Well, not that I have done much of EE development the last couple of years, but I can only agree with people like Adam Bien. The different technologies in the EE stack are so well integrated now and the tooling (NetBeans, Eclipse, IDEA) is so well designed, that you can develop and deploy a simple web application in no time. If you don’t believe my humble opinion, you can follow Adam on twitter.

By doing this I came across the short article, which I want to present you hereby. If you still have your concerns on Java EE’s horribleness, please do read the article and the comments below. It’s quite interesting.

Weld, JSF 2.0 and Google App Engine, part 2

Some time ago I recommended you reading the first part of this short series, where the author guided us in developing a simple web application, that is using Java contexts and dependency injection’s reference implementation (Weld) and JSF 2.0. The most interesting part was that it was configured for and deployed on Google’s cloud offering – Google App Engine (GAE for short).

In the second part the author focuses on several little details that would make your application run better on GAE. It includes database access optimization howtos, security, caching, JSF, logging and also a list of unsupported features. This is very important for those of you who have chosen GAE as deployment platform (for small sites with little traffic it’s perfect as it is free in such cases).

Using Spring Security and Spring Remoting together

In this short article you can see how to wire and configure two of spring framework’s libraries – Spring Security and Spring Remoting, in order to run an application that exposes a web service on the server side and accesses it from the client side.

The Spring fans are a little bit quiet these days, but nevertheless Spring framework remains a full featured application stack that can be used for rapid and reliable application development both for the enterprise as well as for the home users. BTW this week I came upon this presentation about Spring DM server. It is something like a true Java EE application server built on the OSGi technology. It has bundled all the necessary Spring libraries as well as all kinds of dependencies that you normally pack when you are developing a web application on Tomcat. And it does all the dependency injection and provides you all the helper classes that you would need to handle the resources through the whole stack of your application. And it is now free and open source, and it is part of the Eclipse projects.

Wow, enough of Spring evangelizing from my side :-).

Levels of REST architecture

Martin Fowler has a very interesting approach of describing what REST is. It is actually inspired by a book on REST, which is in the process of writing and by a REST model that was presented elsewhere.

Martin develops the REST idea through discussing the implementation of a simple use case where he looks for the vacant hours of his doctor and tries to book one. The implementation goes through three levels of REST-fulness so that the reader can fully understand all the concepts of the protocol – resources, actions (or verbs) and resource representations.

Memory saving pattern: object list

Finally something in the core java area. Although it does not happen very often, we sometimes need to create a complex “multimap”. Author’s use case was a map, which values were lists of objects. The objects themselves were tuples of a String and int.

The author tested the performance and the memory consumption of three implementation of this structure. He first created a StringAndInt class that contains the tuple’s two properties. Then he checked how a HashMap that has a value ArrayList of this class performs in terms of memory. Next he tried the same thing, but instead of ArrayList, he put the new class into an array. The difference was quite small.

Finally putting the array inside the class (StringAndInt class containing arrays of ints and strings) improved much the performance. Why? Try it or read the article and you’ll find out. :-)

Introduction to Mercurial

The distributed version control systems (like Git or Mercurial) are very much discussed and used these days. Shortly after announcing his “retirement” from active blogging, Joel Spolsky contributed this very helpful introduction to Mercurial.

It starts with a chapter for developers like me, that are used to the Subversion style of work. Well, people, if we want to be cool, we have to change our mindset. The least thing that we will get is committing at any time, from any place (even the plain) without bothering of breaking other people’s work or needing network access all the time. What else do Mercurial and other distributed version control system provide? Well, read the introductory tutorial… :-)