Writing cleaner Java code with eclipse

It is always helpful when a tool encourages you to write ‘good code’. Eclipse has some excellent plugins like PMD and FindBugs for analysing and improving your code. But did you know that Eclipse actually has some useful built-in tools to help you?

I found a useful feature of eclipse, to help me clean up my code before I test or commit any of it.
If you go to ‘Window’ -> ‘Preferences’

I’m sure you have been in here before,
But now go to ‘Java -> ‘Compiler’ -> ‘Errors/Warnings’

Now there are lots of useful clean code building features you can edit.

I use the Unused imports and local variables unread, as many times writing new code you add variables that you later end up not needing. This is a good way to highlight them to you. You can also set the options to show a warning or fail – so that your code will not compile and Eclipse will show an error. You will then have to actually fix the issue then and there.

It also allows you to turn all those annoying warnings off so that you can see the errors in the right side bar of your code display window (those blue and yellow, and sometimes red, square markers).

If you turn them all on, you will probably see loads of errors or warnings. So if you are new, a good strategy is to turn them on individually over a period of time and deal with the issues over a period of time. This also lets you test your changes gradually and reduces the chances of breaking something. It is a good end of day 15 minute task.

Do you have any favourite features that help you in developing your code?

Related Posts:

The following two tabs change content below.
Chris developed much of the Forms handling code and also the hooks for the XFA.

About Chris Wade

Chris developed much of the Forms handling code and also the hooks for the XFA.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>