I’ve been a huge fan of the ‘
final‘ modifier in Java for function arguments and variables. While there’s some debate on their usefulness for performance, they definitely add in readability and understanding of code as developers are instantly notified by modern IDE’s and when they try to reassign such values as the compiler will indicate the error.
NOTE: Use of final for classes or functions often contradicts the paradigm of Object Oriented programming as you’ll be restricted from extending or overriding those items!
Categories: Work argument, code, compiler, final, ide, j2ee, java, keyword, modifier, performance, value, variable
I’ve found that many developers still use the classic coding style on JSP’s, unfortunately this makes it difficult to use some common tools for validation and complicates matters when looking for improperly nested tags in the markup. Migrating the XML formatted JSP markup simplifies matters and makes it possible for developers to quickly identify many problem areas of code within the IDE.
<%@ page language="java" %> = <jsp:page.directive language="java" />
<%@ page contentType="text/html; charset=utf-8" %> = <jsp:page.directive contentType="text/html; charset=utf-8" />
<%@ page import="" %> = <jsp:page.directive import="" />
NOTE: you can combine page.directive’s to a single tag with all attributes.
<% //some scriptlet %> = <jsp:scriptlet>//some scriptlet</jsp:scriptlet>
<%! String somevalue="1"; %> = <jsp:declaration>String somevalue="1";</jsp:declaration>
<%= somevalue %> = <jsp:expression>somevalue</jsp:expression>
<jsp:include page="" />
<jsp:directive.include file="" />
<jsp:useBean id="" scope="" type="" />
<jsp:setProperty name="" />
Unfortunately, there’s one common type of tag that does not have an XML equivalent:
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld" %>
Categories: WebStandards, Work code, coding, html, ide, jsf, jsp, jstl, nesting, tag, taglib, validation, xhtml, xml
I’ve previously written on the benefits of static analysis of java code with the use of PMD and FindBugs. I was recently turned on to a new tool that performs similar testing of code within the Eclipse IDE.
When I first found this tool it was free, since that time it’s come out of beta and is now a little costly, but it may still be worth it due to the functionality it provides.
The premise of this tool is a little different than other ones, while it covers much of the same need, it also performs many tests that I would previously use CheckStyle to do. This only provides them at runtime and in a common manner within the IDE.
Categories: WebStandards, Work analysis, code, eclipse, ide, java, javadoc, performance, plugin, standards, static
I typically use the open-source Eclipse IDE for most of my Java and PHP work. For my corporate work, this means that I use IBM‘s packaged RAD and WSAD offerings that are based on various versions of the Eclipse framework.
When working on Internationalized (I18n) applications, most experienced Java architects rely on ResourceBundles to store the various text that is needed for different languages, problem is that editing these files becomes problematic, especially when dealing with multi-byte character sets as are often used in Unicode (non Latin-1, aka ISO-8859-1) languages.
The best editor I’ve found for this case is, as you may have guessed, free for download.
Here’s the links:
Categories: WebStandards, Work eclipse, free, i18n, ide, java, jsp, l10n, plugin, rad, rbe, resourcebundle, unicode, utf-8, wsad
I recently found out about ‘static analysis’ of Java code. I’ve found two of these tools that are both free and easy to use. Both provide review of java bytecode and look for common development errors and inefficiencies…
FindBugs is based on the concept of bug patterns. A bug pattern is a code idiom that is often an error. Bug patterns arise for a variety of reasons:
- Difficult language features
- Misunderstood API methods
- Misunderstood invariants when code is modified during maintenance
- Garden variety mistakes: typos, use of the wrong boolean operator
PMD scans Java source code and looks for potential problems like:
- Possible bugs – empty try/catch/finally/switch statements
- Dead code – unused local variables, parameters and private methods
- Suboptimal code – wasteful String/StringBuffer usage
- Overcomplicated expressions – unnecessary if statements, for loops that could be while loops
- Duplicate code – copied/pasted code means copied/pasted bugs
Both integrate easily within Eclipse based (and other IDE’s) is typically done with the use of a simple plugin.
FindBugs can also run as a Java WebStart (JNLP) application, however a different UI is shown for JRE 1.4 vs. 1.5 and above (look out!).
While no tool can identify all problems, these will help you find some troublesome problems and give you areas to take a deeper look at.
Happy reviewing and fixing.