Java Refinery

Random ruminations of a java developer

Thursday, March 26, 2009

5 essential eclipse java plugins

This is a list of eclipse java plugins I think every java developer should install and use. The tools listed here increase dramatically the quality and speed of development. All of the tools are free and they do a good job, so there really is no reason not to install these plugins. Trust me, your code will be higher quality.

1) EclEmma

EclEmma is a free code coverage tool, it displays graphically the code coverage from a unit test run. If you write unit tests for your code (and you absolutely should!) this tool helps you to pinpoint the parts of code which are not executed during test runs.

Tool homepage:
Eclipse update site:

2) FindBugs

FindBugs is a static code analyzer which you can run for any part of your project. Hightly recommended. One caveat is that you have to carefully weigh the advice these source code analysis tools give and not to blindly correct each reported issue. But this applies to all code checking tools.

Tool homepage:
Eclipse update site:

3) Jadclipse

Jad is maybe the best java decompiler there is, and jadclipse is the eclipse frontend to it. This tool is immensely useful if work with any third party libraries or code to which you don't have sources.

Tool homepage:
Eclipse update site:

4) Anyedit tools

Anyedit tools adds a new context menu to eclipse which can be used for many useful tasks, like converting from underscore notation to camelcase etc.

Tool homepage:
Eclipse update site:

5) PMD

Another code checking tool, massively useful for any java developer. FindBugs and PMD report possible bugs with slightly different approach, use them both! 

Tool homepage:
Eclipse update site:

Saturday, May 05, 2007

Using JMeter regular expressions with regexFunction

This short tutorial will help you use JMeter regular expressions using regexFunction.

RegexFunction is a useful helper designed to aid in parsing values from the previous response using regular expressions. I've found it useful to use regexFunction to follow a particular link when the link href values are dynamic values, which is normal in web applications. The simplest usage is to create a http request sampler and add the regexFunction to the path field, this allows you to follow complex links from the tested web application.

The basic form when using the regex function is this:


This will insert the result of the regexp match as a variable to this position (for example the path textbox in http sampler). Note that this example does not use arguments 4,5 and 6, they are given no values with the ",,,".

Arguments to the regexFunction

Argument #1: the regular expression to be used
for example:

"(.*)">this is a link

Matches a link of this form <a href="someurl">this is a link</a> AND stores the url of the link as the result. This is useful when following links which have dynamic content such as session id's etc.

Argument #2: The template string which will be used to refer to the evaluation result, the syntax is $[text]$, for example $1$.

Argument #3: This is the match number which JMeter should be using. The value can be:

* Any integer, this is what I've used almost always.
* RAND which means "select one of the matches randomly".
* ALL which uses all of the matches and concatenates them together.
* float from range of 0-1 which instructs jmeter to select the match number using the following formula: number_of_matches * supplied_number

Argument #4: If ALL was used in argument #3 this tells the delimiter to use between matches. (I've never used this)

Argument #5: Default value to be returned if nothing matches.

Argument #6: The reference name for values parsed by this function. (I've never used this either)

Thats it, this is the basic usage of the regexFunction in JMeter.

Thursday, August 24, 2006

Quick JSP (Java Server Pages) Programming Tutorial

This is a quick tutorial of the JSP technique. JSP pages are used with Java application servers, for example Tomcat, Weblogic or Websphere.

Some quick facts before we get going into more details:

-JSP files are executed at server.
-JSP files contain HTML + varying amounts of embedded Java code. (There's a bit more though, like tags and EL, but you can ignore them when beginning)
-When a web user surfs to an address like, this jsp page is executed at the server, and the result is a normal HTML page for the client browser.

Very easy so far?

JSP has two styles of embedding Java code into JSP:

1) Java expression:

<%= java expression %>

This first style is used when you want to output the result of a simple java expression into the resulting HTML. For example:

<%= customer.getName() %>

Notice that there is no semicolon (;) here.

2) A block of Java code:

<% // java code %>

This style is used when you want to execute larger blocks of code. For example:

Customer customer = new Customer();
customer.setName( "customername" );

Importing classes

The import is a bit different from normal Java imports. It goes like this:

<%@ page import="java.util.List,

Which functions in identical way to this java class import declaration:

import java.util.List;
import java.util.Iterator;

The JSP import declaration should be in the beginning of the page, just like a normal Java import.

Outputting strings to resulting html from code blocks

This is easy:

<% code...
out.println( "foo" ); code...

Thats it , now you are ready to code JSP pages. There is more stuff, but this will get you started with producing real results.


Tuesday, August 22, 2006

Novice Java Programmer Mistakes, part 1

I've done a lot of code reviews over the years and the same mistakes always pop up. Often they are really trivial ones like this one, maybe I'll write a top 10 of these some day :)

Using == when really should be comparing objects with equals()

String a = "aa";
String b = "bb";

if( a == b ) // this is wrong
// do something

The previous example of course really should be like this:

if( a.equals( b ) ) // this is correct
// do something

Here's an additional tip, when comparing string literals to some String variable its quite useful to write the comparison like this:

"foobar".equals( a );

This makes it possible to leave out the null check, which in turn results in cleaner code.


Sunday, August 20, 2006

Web application testing with JMeter

Jmeter is a useful tool for testing applications, I have mainly used it for web application testing, it can be used for other types software too. The target application does not have to be a Java application.

When developing web applications its essential to load test the application early and often. Using JMeter it is easy to have a working load test script ready all the time while working on the application.

Creating a simple web application test is easy with JMeter, just add a thread group, add some http requests to the group and go. This is the bare minimum test script.

To actually get some meaningful results you need to add some type of listener, for example graph listener which shows graphically the number of requests served by the web application. The numbers it shows include throughput and the average response time, this is very useful to get a quick look at the application performance.

For testing more complicated web applications you need to create some regular expressions for parsing the resulting response pages. This might sound complicated but it is really easy, I will write about this in another post.