Format code in Eclipse

While coding we have to deal with many loops and if conditions. Due to this, we forget to maintain proper spacing between lines and character. As result the code becomes difficult to read for some other person.

So instead of organizing/formatting the code manually in Eclipse we can format the code on a single click. Let us see how it can be done :-

Using Shortcut

Go the program that you wish to format and press Ctrl+Shift+F to format the code quickly.

From MenuBar

In the menubar of Eclipse go to Source and then select Format from the dropdown to format the code.

Now let us see how formatting of code actually makes our code more readable and easier to debug in future. In the below 2 images first code is not formatted and the second code is obtained after pressing Ctrl+Shift+F.

Less Readable

Now we press Ctrl+Shift+F to format code and obtain the below code in eclipse :

More Readable

As you can see code in second image is better organised and more readable. It is a good practice to format your code to make it more understandable and readable.

Let us see how to Generate Getter and Setters in Eclipse.



Ankit is a computer adventurer who loves to explore different things related to technology. He has been associated with technology and coding from past 10 years.

View all posts by Ankit →

Leave a Reply

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