Java Code Quality


Most tech leads will readily admit that in large development projects, a major chunk of their effort goes towards ensuring good code quality.  With the increase in number of developers, there is greater need for standardization the code which is enforced in the form of adherence to certain code quality.  As a programming language, Java if fortunate enough to have several coding conventions defined by several companies including Oracle (Sun).  However every company or even individual projects within a company often supplement the general standard with it’s own set of custom guidelines, rules and conventions.

Just like everything else in life, it is a simpler matter to define standards / guidelines.  However it is an entirely different ball game to follow them.  For architects and tech leads it is a question of ensuring the adherence.  So, we are constantly on the lookout for efficient ways to accomplish this.  One of our favourite tools is the Sonar – Java static code analysis tool from Sonarqube.

Here are some quick steps on how to get up and running with Sonar on a Mac system.  Hope you find it useful.

Set up Sonar

Here’s a great link that i found

1. Download sonar into some directory
For eg /Users/madheshr/tools/sonar-3.7

2. Create the sonar schema on MySQL

3. Edit in the conf directory and make below changes

– Specify DB parameters
– Webhosting mechanism: default is

4. Create a startup script to start sonar
/Users/madheshr/tools/sonar-3.7/bin/macosx-universal-64/ start &
Analyzing a project using sonar-runner

1. Download sonar-runner and extract it

2. Edit conf/ to mention webserver name and DB name

Note: The default script has mismatched sonar schema names.
3. In the project home create a file Note it is case-sensitive
Also confirm the path from which java code starts. May not be the main src itself

# required metadata

# optional description
sonar.projectDescription=Admin utility for iRecon

# path to source directories (required)

# The value of the property must be the key of the language.

# Encoding of the source code

4. Run using command sonar-runner

As always, all the mistakes are mine and all the credits go to the open source community.


%d bloggers like this: