Wednesday, 31 August 2011

Installing Weblogic Server on Your Mac

Installing Weblogic Server on an Apple Mac doesn’t come naturally. The usual technique is to download and, with a bit of fiddling about, install the generic package installer aimed at Solaris.

Oracle seemed to have improved things, however, by bringing out a Weblogic Zip distribution for development purposes that can be easily installed on Windows, Linux and Mac. You can download this from the following link: ...assuming that you already have a developer account.

Tuesday, 30 August 2011

Enabling the root Account on Your Mac

There are several ways to enable the root account on your handy-dandy Apple Mac. The simplest one I can think of is to open a terminal window and type the following:

%   sudo passwd root
Enter Password: {type your current password here}
 Changing password for root
New password:  {type your new root password here}
Verify password: {re-type your new root password here}

Monday, 29 August 2011

Developing Enthusiasm and Excitement

I went on a course a few weeks ago for the first time in about 12 years. I was learning about a well known content management system. The course was split into two parts: firstly, the principles and use of a content management system (CMS) and secondly, developing a presentation layer using their web application framework. I have to say that I was really impressed by the ideas on CMS, especially the idea that you can have large numbers of people that, given the right tools, can contribute to a web site with only a bit of common sense and without any real technical knowledge. An example would be a whole load of reporters constantly updating a news website. Brilliant.

Friday, 26 August 2011

Subversion: Attempted to lock an already-locked dir

Earlier today I was committing some changes to a local Subversion repository running on a PC when Windows decided it was too busy to co-operate and told me that it was “Not Responding” (which is not unusual). Spring's STS program (aka eclipse painted green) running on my handy-dandy Mac hung and then crashed (v. unusual) leaving the commit half complete.

On restarting STS, I again attempted to commit my work and got this error:

Thursday, 25 August 2011

The Ten Minute Build

Given a development environment any developer should be able to get hold of the source code, click a button or type a simple command and run a build. The build should compile and perform its unit tests within about ten minutes. This is the Ten Minute Build rule in James Shore’s and Shane Warden’s book The Art of Agile Development and it’s easy to see why this is a good idea because builds that don’t run easily are both frustrating, which lowers moral, and burn project time shovelling your company’s money into some metaphorical furnace.

Wednesday, 24 August 2011

Declarative Unit Testing: Is JUnit Obsolete?

One of the pains in the bum with Test Driven Development is that if (or when) you change a class, you often spend a good deal of time patching up all your unit tests and if you’re a Mockist then it becomes even harder as you have to mess around re-jigging a lot of mock code. So, the other day I was surprised when I came across a new free product that turns the current ideas of unit testing on their head. The surprise came in the form of SureAssert, which as the website says is “an integrated Java unit testing solution for Eclipse”.

Tuesday, 23 August 2011

RC4 Encryption

Bazinga! I hope that everyone who read yesterday’s ROT13 blog spotted the Sheldon Cooper-esque 'clever prank' for the more secure double ROT13 aka ROT26 algorithm. Today’s blog takes encryption one step further and covers the hugely popular RC4 encryption algorithm developed by Ron Rivest, indeed the RC stands for Ron’s Code. Although now broken, the RC4 algorithm is still widely used in protocols such as SSL and WEP.

Monday, 22 August 2011

ROT13 Encryption

I thought that today I’d tackle the thorny issue of encryption starting with one of the most simple and weakest algorithms available: ROT13. ROT13 is a simple character shift or Caesar (or Caesar’s) cipher. In ROT13 each plain text character is replaced with one that’s 13 characters further along the alphabet. For example: ABC becomes NOP, whilst the plain text characters after M loop around back to the start of the alphabet; hence: MNO becomes ZAB whilst XYZ becomes KLM. Note that only upper and lower case letters in the English alphabet are encoded.

Friday, 19 August 2011

Code Formatting in Agile Teams

Whether you work in an Agile team or not, one of the crucial aspects of team work is agreeing your team's code formatting rules. You may wonder why I’m using the word crucial when introducing this topic and the answer lies in the consequences of not using a common style.

Thursday, 18 August 2011

Adding the Blueprint Toolkit to your Spring Webapp

If you’ve ever taken a look at the Spring MVC sample code, you’ll notice that the screens have a certain style and digging deeper into the JSPs you’ll find that the apps use a number of CSS classes with their <div>s tag such as container and span-12.

Wednesday, 17 August 2011

Tuning your Server's free pool

When writing an EJB for the Weblogic Server, there is a really useful vendor specific deployment descriptor called weblogic-ejb-jar.xml. This file contains many different properties that can be used to tune your application and today’s blog examines two of these: initial-beans-in-free-pool and max-beans-in-free-pool, which apply to stateless EJBs and MDBs.

Tuesday, 16 August 2011

How Big Should a Function Be?

The other day I was talking to a colleague; we were comparing horror stories about the largest functions that we’d ever seen and I quoted a 14,500 line absolute monster that I’d seem a long time ago that was part of a stock settlement system written in C++ and, oh how we laughed. This got me thinking that you never really see many opinions, recommendations or rules of thumb for the optimum length of a function, so when it comes down to it I like to quote Bob Martin’s two rules covering the length of a function from his book ‘Clean Code - A Handbook of Agile Software Craftsmanship’: "The first rule is that they should be small. The second rule is that they should be smaller still".

Monday, 15 August 2011

More on String and the StringBuilder Performance

In February, I demonstrated the most efficient way I could think of for conditionally building a string. This compared the use of StringBuilder and the ‘+=’ operator whilst checking for null values. The results showed that StringBuilder.append(..) was much faster than using ‘+=’.

Today’s blog covers the much simpler scenario: trying to decide which is the quickest way of of creating a simple string. In order to test this out, I modified the code I’d used last time adding a couple of new methods:

Friday, 12 August 2011

Wrapping Java API Classes

The benefits of using TDD to write your code are well known; the idea that you can write simple, independent, repeatable tests that will challenge your class is a lynch pin of today’s software industry. There are those classes, however, in the Java API, usually the ones that have been around for a long time, that are written in such a way as to make testing difficult and the reason this happens is because they don’t implement an interface or communicate with some external resource.

Thursday, 11 August 2011

Is ‘Convention Over Configuration’ Going Too Far?

I’m all for convention over configuration, especially in frameworks such as Spring and I really like the idea that the Spring XML configuration file can boil down to one line:

<mvc:annotation-driven />

...and there’s even argument for suggestion that if the XML config file is missing from your project then Spring should assume that your application is annotation driven and attempt running - though I’m not too naive to assume that more thought would be needed here as this may have other ramifications.

Wednesday, 10 August 2011

@DateTimeFormat Depends on Joda Time

Yesterday’s blog explained the use of the @DateTimeFormat and whilst writing it, I purposely chose to use java.util.Calendar for simplicity as I didn’t want to add an unnecessary dependency into my classpath... and that’s where I came unstuck. I turns out that if you don’t have the following dependency in your POM:

Tuesday, 9 August 2011

Using the Spring 3 @DateTimeFormat Annotation

@DateTimeFormat is the complimentary annotation to yesterday’s @NumberFormat and like @NumberFormat it does what it says on the tin and allows you to format dates and times. The Spring javadoc states that it can be applied to java.util.Date, java.util.Calendar, java.long.Long, or Joda Time classes and works on dates sent to the presentation layer from the controller and visa-versa.

Monday, 8 August 2011

Using Spring 3 @NumberFormat Annotation

The Guys as Spring have provided a very useful annotation called @NumberFormat that allows you to, well... format numbers. It works on numbers sent to the presentation layer from the controller and visa-versa and can be applied to any class derived from java.lang.Number. It will format numbers into three styles as defined by the NumberFormat.Style enum: CURRENCY, PERCENT and NUMBER.

Friday, 5 August 2011

The Spring MVC-Ajax Sample and its JSON Library

The Spring-MVC sample code is available from the Spring subversion repository at The idea of this sample is to demonstrate a simple Ajax application that updates an account screen both checking that a user name is available and adding a new account to the application.

Thursday, 4 August 2011

Adding JQuery to your Page

JQuery is probably the most popular Javascript library available today and given its flexibility, and the enormous number of plugins it’s not difficult to see why. There are two versions of JQuery available, a production version and developer or debug version, and at least two ways of including it in your page.

Wednesday, 3 August 2011

The JSR 303 javax.validation.Payload Class - WTF???

During the course of my last few blogs I’ve covered quite a few features of the JSR 303 Valdator and there is one feature that I’ve avoided looking into until now and that's the payload attribute of the constraint annotation interface.

There’s not much on this Hibernates documentation, and I couldn't find an entry for Payload in the JSR 303 Javadocs (if you know of one please let me know), so it raises the question of what it’s for... Looking at Hibernate’s documentation it states that: “an attribute payload that can be used by clients of the Bean Validation API to assign custom payload objects to a constraint. This attribute is not used by the API itself.” From this, you’d think that wouldn’t have to include it in your custom constraint declaration, but try taking it out and nothing works. This means that the validator is reflectively checking for its presence even though it’s not using it. Something smells fishy here.

Tuesday, 2 August 2011

Using the JSR 303 @GroupSequence Annotation

Yesterday’s blog covered JSR 303 groups, and today’s blog builds on that idea and demonstrates how to use the @GroupSequence annotation using the beans and custom constraints mentioned previously.

If you need to find all my blogs on JSR 303, then I suggest that you click on the ‘JSR 303’ label in the cloud below. They all follow the same Address bean validation theme.

Monday, 1 August 2011

Using JSR 303 Validation Groups

Anyone who’s looked at the code for a JSR 303 custom constraint will have noticed that the annotation interface declaration contains a couple of less than obvious attributes: groups() and payload as demonstrated by the @Country custom constraint below:

@Target({ ElementType.METHOD, ElementType.FIELD })
@Constraint(validatedBy = CountryValidator.class)
public @interface Country {

String message() default "{country.constraint}";

[] values() default "UK";

[] groups() default {};

extends Payload>[] payload() default {};

This blog covers the groups attribute in an attempt to explain its purpose.