Scroll to top

Java code cleanup using eclipse

Have you ever wanted to clean up your code? Remove unused imports or variables ?  Eclipse provides this feature, all you have to do is to create a profile !!  Here’s how its done.

Steps to Create Profile in Eclipse

Go to Windows >> Preferences >> Java >> Code Style >> Clean Up Click on New button.

In the next window provide a Profile Name of your choice for eg.  JBT and click “OK”. It will take you to a new window where you can configure your clean up options.

There are different tabs provided that allows one to set their preferences for the  profile.

Listed below are the clean up options.

Code Organization


  • Format Source Code
  • Remove Trailing Whitespace
  • Correct Indention


  • Organize Import


  • Sort Members (Caution)

Code Style

Control Statement

  • Use blocks in loop Statements
  • Convert for Loops to Enhanced for loops


  • Use Parentheses in Expression (Caution)

Variable Declaration

  • Use final modifier wherever possible (Caution)

Member Access

Non Static Access

  • Use ‘this’ qualifier for field access
  • Use ‘this’ qualifier for method access

Static Access

  • Use Declaring class as qualifier (Caution)

Missing Code


  • Add missing Annotation (Caution)

Potential Programming Model

  • Add Serial Version Id

Unimplemented Code

  • Add unimplemented Method (Caution)

Unnecessary Code

Unused Code

  • Remove unused Imports
  • Remove Unused Private Members
  • Remove Unused local Variables

Unnecessary Code

  • Remove Unnecessary Cast


How to Apply the Profile

Select an application where you want to apply the  newly created profile (JBT). Right click on it and go to Source >> Clean Up. A window will appear as below.

Select Project and Profile and click “Finish”.

Now you know how to clean up your code with the help of Eclipse. I have already created a profile and added for you with preferred settings. Just import attached file in your eclipse and start using it with your code.

How to Import Profile XML

Go to Windows >> Preferences >> Java >> Code Style >> Clean Up Click Import button and select XML file. JBT

Author avatar

Post a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.