Showing posts with label software. Show all posts
Showing posts with label software. Show all posts

Wednesday, April 20, 2011

Unnecessary Code Detector (UCD)

I'm currently working on a couple of years old Spring-based Java application. The application is developed and extended by multiple developers, which is clearly visible in the code. I'm responsible for a feature change that is going to have a big impact on the code.

An important step before implementing the new feature, is to refactor the relevant parts of the application in order to make the change easier to implement (and more understandable).

I noticed that parts of the code or modules are probably not used anymore. To make the refactoring process easier and more effective, it's probably a good idea to locate and remove dead code. Refactoring dead code is a waste of energy! I've found an Eclipse plugin in the Eclipse Marketplace called Unnecessary Code Detector, which helps me locating dead code.

A first run of UCD results in a bunch of markers on code locations, where UCD thinks the code is unused. It also places markers on locations where the "visibility" of variables and methods could be improved.

The tool enables me to quickly find classes and methods with no references. I always do a double check with a "text find" on the whole project, to make sure the code is really not used. Because I'm using Spring, some of the classes are only referenced and used in the XML file. This type of reference is not detected by UCD, and it results in false positives. I annotate these locations with @SuppressWarnings("ucd"), which will stop UCD from marking them as unused code in the future.

In my opinion, Unnecessary Code Detector is a very valuable tool for the Java Developer. Give it a try!

Monday, June 21, 2010

Sonar (Code Quality Management System)

Sonar is an open system to manage code quality. It monitors the 7 axes of code quality:

  • Architecture & Design
  • Comments
  • Duplications
  • Coding rules
  • Unit tests
  • Potential bugs
  • Complexity


More info: http://www.sonarsource.org/

Saturday, April 10, 2010

Java web application project directory structure

The directory structure I use for Java web projects is based on the Java Blueprints Guidelines recommended by SUN.

/webproject/ (the project root directory)
/webproject/build/ (this directory is packed into a WAR-file)
/webproject/test/ (system wide test files)
/webproject/setup/ (configuration files for container or project)
/webproject/dist/ (contains the WAR file)
/webproject/lib/ (libraries/jars)
/webproject/src/
/webproject/src/java/ (Java sources)
/webproject/src/conf/ (configuration files for build process)
/webproject/src/test/ (unit tests)
/webproject/docs/ (documentation)
/webproject/web/ (the web root starts here)
/webproject/web/WEB-INF/
/webproject/web/WEB-INF/jspf/*.jspf (JSP fragment/include files)
/webproject/web/WEB-INF/lib/
/webproject/web/WEB-INF/tlds/
/webproject/web/WEB-INF/tags/
/webproject/web/WEB-INF/faces-config.xml
/webproject/web/WEB-INF/web.xml
/webproject/web/*.jsp
/webproject/web/*.html
/webproject/web/css/ (CSS-files)
/webproject/web/img/ (images)
/webproject/web/js/ (JavaScript files)
/webproject/LICENSE.txt
/webproject/README.txt
/webproject/build.xml (ANT build file)

In the future, I'll post the ANT build file, which is used to automate build and package processes.

Friday, March 12, 2010

Sun Certified Enterprice Architect 5 (SCEA 5) Notes

The notes I have made while preparing for the SCEA 5 exam can be found at http://scea.djcheng.com. Compared to the other more technical exams like SCJP, SCWCD, and SCBCD, this exam is really a mile wide, an inch deep. I had more fun preparing for it than other exams. Most of the time the answer of an exam question is not technical incorrect, but only not the best anwer in the specific context compared to other answers.