14

I am using Eclipse Helios Version as an IDE and developing code using Java.

The good thing for me is that the code works well, but the bad thing is that the code doesn't look good ( I mean spaces and brackets used in control structures used in if-else statments as well as for and while loops scattered here and there )

I have used Ctrl + Shift + F , as well as an online tool (http://www.prettyprinter.de/) for formatting , and with this it looks more worse.

As a lot of developers are out here, how do you arrange your code properly and how you make it look good.

Please tell me , I am worried as some senior person might review the code .

3
  • Don't you have some kind of corporate standard for how java code should look? Before you start creating your own rules, make sure you check if there already are some rules you should follow. Commented Nov 8, 2011 at 8:22
  • Use the built in formatting tools that are provided with eclipse. In my experience PMD/Checstyle/Findbugs only identifies where the issue is at, but doesn't actually fix any issues. Commented Nov 9, 2011 at 3:24
  • 9
    Bro, thanks for "Ctrl + Shift + F" - that's what I've been looking for. LOL. Commented Sep 19, 2012 at 14:41

3 Answers 3

9

Try to change Window->Preferences->Java->Code Formatter->LineSplittin-> Maximum Line length up to 120 or 140 symbols.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much , IS this true that PMD helps in beautifying the code in eclipse ?? If so , could anybody please tell me how to beautify code using PMD ?? because i think that PMD is only for checking coding standards .
Unfortunately I've never used PMD. But according the text on the project main page it's just a code style checker
6

To change the settings of the code formatter, go into the following menu:

  • Windows
  • Preferences
  • Java
  • Code Style
  • Formatter

And then create your own format in however a form you choose.

1 Comment

This is by far the best suggestion so far. I have also added extra steps when I save a source file, such as optimizing imports, removing extra spaces, formatting Javadocs and comments, etc.
3

You can install PMD and FindBugs plugins. The PMD tools can help you to optimize code.

The quote:

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.