Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

15 Productivity Tips for Eclipse Java IDE Users

DZone's Guide to

15 Productivity Tips for Eclipse Java IDE Users

Here is one dev's advice for using Eclipse more efficiently from coding to debugging, including favored keyboard shortcuts and tooling.

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

With over 10 years of releases and countless extensions and plugins, Eclipse remains one of the most popular IDEs for developers working across several domains. Especially those in the Java ecosystem, where Eclipse provides a solid environment for developing, debugging and running applications. In this post, I'd like to share my favorite features in Eclipse that help me be more productive in my daily work as a Java developer. These features don't require any plugin to be installed if the very first tip is followed.

1. Use Eclipse Oxygen

There are many improvements in the last release of Eclipse alone, and with the latest build released just a few days ago, the IDE supports Java 9 out of the box. Some of these improvements are:

  • Showing the last returned value while debugging a Java program. This shows you the value returned by the last method after stepping through the program statements.

  • Better Java 8 support, with numerous bug fixes for lambda expression type inference.

  • A new Java index that significantly improves tooling performance, such as when loading the type hierarchy of platform classes and interfaces.

  • Support for JUnit 5.

You can find a list of Java tooling improvements in Oxygen here.

2. Switch Editors Using Ctrl+Tab

If you're used to switching tabs in browsers and editors like Notepad++, then do yourself a favor and change the keybinding for switching between Java source files. Go to Window -> Preferences -> Keys, then search for "Next editor" and "Previous editor", and override their bindings to Ctrl+Tab and Ctrl+Shift+Tab respectively (note: I'm using Windows).

3. Group Related Projects in Working Sets Before Choosing Multiple Workspaces

If you work on many different projects, at some point you may need to use multiple workspaces to separate them. But before reaching that level, you can just group related projects into a working set. This way you don't have to switch workspaces or have two Eclipse windows using different workspaces. It also keeps your projects organized and accessible from within the same view. For example, I typically keep a working set for sample projects for quick experimentation, and then typically a working set for each group of related modules in a Maven project. One thing that you may need to do is change the Package Explorer view to view these working sets as shown below.

Image title

I often end up with many working sets containing projects I'm not using. In this case, I can simply close a working set by right-clicking on it from the Package Explorer and selecting Close Project. This reduces memory consumption in the IDE and makes it as if these closed projects do not exist in your workspace anymore until you re-open them. Only when I have too many working sets, or I have projects that considerably differ from each other that I rarely switch between, then I separate them in different workspaces.

4. Set The "Incremental" Option in the Search Dialog

When you hit Ctrl+F to find text in a source file, check the Incremental checkbox in the search dialog to make the occurrence of the searched text appear as you type. This seemingly minor detail helps me avoid typing too many characters and then hitting return to find what I want.

Image title

5. Use Navigation and Search Shortcuts 

Here are a few shortcuts to help to understand your code (using Windows). These are so useful that eventually, they'll easily become second nature:

  • F3 or Ctrl+Left click: goes to declaration of element

  • Ctrl+T: view type hierarchy and implementation methods

  • Ctrl+Alt+H: view call hierarchy of selected element

  • Ctrl+Shift+G: search workspace for all references to selected element

  • Ctrl+Shift+T: search for a class, interface or enum

  • Ctrl+Shift+R: search for a resource (e.g. text file)

6. Use the File Search Feature

This is really helpful if you want to search files in your workspace for text. The search can be filtered by file type and scope of the search, such as searching only the selected project.

Image title

7. Use Ctrl+Space and Ctrl+1 for Content Assist and Quick Fixes

Ctrl+Space allows for auto-completion. It can also be used to override methods and generate getters /setters and constructors.

Ctrl+1 can be very handy in quick and smart fixes such as:

  • Assigning constructor parameters to new or existing class fields

  • Assigning a statement to a local variable

  • Renaming a variable, field or class, etc.

8. Use Code Generation Actions

Alt+Shift+S can be used to quickly add common code:

  • Generating getters/setters and constructors

  • Overriding hashCode() and equals()

  • Overriding toString()

9. Ctrl+3 Is Your Friend

As with any modern IDE, there are many keybindings to do all sorts of actions in Eclipse. But the most important is probably Ctrl+3 for Quick Access which is an entry point to virtually all actions you can do. I typically use it to open a view, but it can also be used to do refactoring, creating a new project, and lots of others.

10. Download the Sources of Libraries

If you're using Maven, you can download the source code of your dependencies. There is preference under Window -> Preferences -> Maven that when selected automatically fetches the source artifacts of dependencies. You can also download sources manually by right-clicking on the dependency in the Maven Dependencies tree and selecting Maven -> Download Sources. Usually, this also makes Javadoc comments available in your IDE when you hit F2, so you no longer need to browse it separately. There is a similar way to do this in Gradle.

11. Use Shortcuts to Run, Debug and Inspect Code

These again should become second nature while debugging:

  • Ctrl+F11 to run the last application launched

  • F11 to debug the last application launched

  • F5 to step into

  • F6 to step over, i.e. go to next line

  • F7 to step return to caller

  • F8 to resume until next breakpoint

  • Ctrl+Shift+I to evaluate selected expression

  • Use the Display view to write and execute code within the current debug context

12. Pinpoint Program Suspension With Conditional Breakpoints and Watchpoints

Often you can make your program suspend on a line of code only when a certain condition is met. This reduces time spent on debugging, as long as you don't overuse the feature (too many breakpoints, especially conditional ones, can make the program run slower in debug mode; in this case, you can either disable or delete unneeded breakpoints).

Image title

13. Save Your Run Configurations for Later Re-Use

I often need to build multi-module projects with different parameters, or run unit tests for a specific project, or configure some parameters for running a main class. Instead of switching to the command line, take the time to configure an appropriate run or debug configuration within the IDE. Ideally, I never want to have a separate command line and everything should be done in the IDE, especially that it comes with all major build tools and SCM plugins already bundled.

14. Leverage Code Coverage Support

In Eclipse Oxygen, the Eclipse EclEmma tool based on the JaCoCo code coverage library is integrated as part of the IDE, which allows you to have information on code coverage when running your unit tests. To run a program or unit test with coverage, right-click on the class to run and select Coverage As -> Java Application or JUnit Test.

15. For Large Workspaces With Lots of Dependent Projects, Disable Build Automatically

If you have lots of projects that depend on each other, the Build Automatically default behavior can be time-consuming because it would trigger an "internal" build upon saving. In this case, you can uncheck it from under the Project menu, which makes you in control of when to manually build your project. For example, after saving all needed modifications, the developer can manually do the internal build using Ctrl+B or using Project -> Build All, or do a full build from scratch using whatever build tool he or she is using.

Conclusion

And those were 15 habits for improving productivity which I hope to be useful for Java developers using Eclipse! Of course, many of them may depend on the developer's preferences, and there are others that are not mentioned.

Check out what's new in Eclipse Oxygen for Java developers. You can also follow the Eclipse Java IDE for more tips and features.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:
java ,eclipse ,ide ,tips and tricks

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}