Top 10 Eclipse Tips and Tricks for Java Developers in 2022

Top 10 Eclipse Tips and Tricks for Java Developers in 2022

Introduction

Eclipse is one of the most popular and widely used IDE when it comes to Java Development.

The first step towards productivity is to change all those "difficult to remember" shortcuts to one which we can remember easily. Because that's the trick, we found shortcuts difficult to remember and eventually stop using them.

To customize shortcuts go to below option in eclipse:

Windows >> Preferences >> General >> Keys

So, without further ado, let's jump into the topic.

1. Open Recent Files

By default, you can open recent files using CTRL+F6 which is uncommon and hence difficult to remember. So we can change it to CTRL+TAB which is easy to remember as most common software has the same shortcut to access the recent files.

Step 1: Open Keys Shortcut settings in eclipse and search for "next editor"

Step 1: Open keys shortcut settings and search "next editor"

Step 2: Change Bindings to Ctrl+Tab and save

Step 2: Change Bindings to CTRL+TAB and Apply

That's it! you are now able to access all open files very conveniently.

Many of us must have used CTRL+H in Eclipse. But it's too slow and takes too much time to give us the search results.

Instead of it, we can use a quick search which is blazing fast and it will list down all occurrences of the search term in all the files in your workspace as you type the search term. By default, it can be accessed by CTRL+SHIFT+ALT+L (this shortcut can be changed as per your convenience)

Quick search to search a term in all files of workspace

3. Conditional Debugging

Imagine you are debugging a big data set, in which you are facing some issue in some element of that list but not sure which one. Normally we will debug all the elements of the list and check one by one which one has an issue, right? There's a better way of doing it.

Conditional Debug: Debug breakpoint only gets activated when some given condition is hit.

Right-click on a breakpoint >> Breakpoint properties

Breakpoint properties to set condition

As shown above, you can put any condition and breakpoint will only get active when that condition is hit. Super Easy! This can save you tons of time.

4. Use Debug Mode to Run Any Java Expression

Suppose you are in a debug mode and want to execute some java expression(which is not part of the code) for your testing many times you will write that piece of code, compile it and debug it again?

Instead of it you can simply write that piece of code in your method and select that much code, and do CTRL+SHFT+i and you can check the results right away. This can be very handy because many times we are debugging some complex scenario for which we've performed those ten different steps to reach that breakpoint and it's annoying if we've to do it again to just check our code snippet.

Run any Java Expression in Debug Mode

5. Working Set

Many a time, we put multiple projects in multiple workspaces and end up using multiple eclipse instances which slows down our development.

Instead of this, we can organize projects in the different working sets, access them when it's required using a single eclipse, and close the working set when not using it. By this approach, we can save extra memory consumed by eclipse instances which speed up our development.

Working sets are a very underrated feature and not many of us use it often! But by grouping, all projects based on their nature in a working set, we can build similar projects together, do some similar operations(search, refactor, find references) on the entire working set, and whatnot. Try it, it's a great way of increasing productivity!

6. Magic Command to Open Anything

Often it's difficult for us to locate all the different options available in eclipse.

CTRL+3 comes to your rescue! With these, you can quickly access any feature in eclipse.

![CTRL+3 to open any option in eclipse](cdn.hashnode.com/res/hashnode/image/upload/..)

7. Download Sources with Maven Build

Whenever download the maven dependency always download its source. It will help a lot to understand the underlying classes and also help debug.

You can put debug inside libraries class just as normal java file.

Download Sources with Maven Build

8. Clipboard History

Often we need to copy-paste multiple texts in one go.

Using More Clipboard plugin we can maintain the clipboard's history, choose texts from the history and paste it wherever we want. This can save you time to go back to some file to copy the text again which can be annoying at times.

Steps to install more clipboard plugins can be found here

clipboard_option_in_ecipse.gif

9. Code Templates

Code templates are a wonderful way of enhancing the code suggestions in eclipse.

Suppose, we want to put below check on some string variables in our code:

if (name != null && !name.isEmpty() && !name.isBlank()) {
    // code goes here
}

Imagine this piece of code is very common in our project so instead of writing this thing, again and again, we can create a code template for this piece of code, and next time when you've got a similar requirement simply do CTRL+SPACE, choose your code template, and boom!

clipboard_in_eclipse.gif

Let's see how to create the above code template:

  • Open Java > Editor > Template in Preferences and choose a new template

code_template_1.png

  • Add the below configuration in the popup window and save

code_template_2.png

Likewise, we can identify all frequent pieces of code which we often use in our project and add custom code templates, and make better use of our time.

10. Bookmarks

Yes, you heard it right! Bookmarks do exist in eclipse too.

With bookmarks, you can save any file location with its line number in eclipse so that you can access it easily when you need it next time.

  • To create a bookmark, right-click in the left margin and choose to add bookmark option:

bookmark_in_eclipse.png

  • To see all bookmarks, open bookmark view:

bookmark_in_eclipse_2.png

Bonus Tips!

  • Prefer "Debugging" over "Running" your project

  • Use incremental search when searching in the file which can start searching as we type.

Incremental Search option in eclipse

Conclusion

In this article, we've seen all the 10 tips to increase our productivity using eclipse.

💖Thanks for Reading!

👋Hi, I'm Vikas,

I am Fullstack Developer👨‍💻 with 8 yo exp!

I am happy to announce that finally I've started my content creation journey on Twitter.

Every Mon, Tue, and Friday I write a thread on Java, Javascript & Fullstack Development.

Follow me on Twitter @vikasrajputin for more such content.

Happy Coding :)