Eclipse for Java developers: Keyboard shortcuts | Part 3

I want to present you some more keyboard shortcuts that you can use in Eclipse for Java Developers. These shortcuts mainly help you to navigate through the source code so it may be especially helpful if you are working on a project that you are not really familiar with yet. I’m using macOS so if you’re using Linux or Windows the standard shortcuts may be a little bit different.

Open Declaration: F3 / Cmd+Click

You are working on some code and you haven’t seen the implementation of a certain method yet then you can position the cursor on the method’s name and press F3; alternatively you can hold Cmd and left click with the mouse on the method’s name. This will take you to the declaration of the element you selected. This works on classes, enums, interfaces, methods and variables.

References in Workspace: Shift+Cmd G

If you are refactoring existing code and need to know where a certain method is used then just position the text cursor on the this method and press Shift plus Cmd and G. The search view will be focused and all the references in the workspace will be displayed. Simply click the plus icon in the search view to expand all the findings in the result set.

Open Type Hierarchy: F4

Extending classes or implementing interfaces are basic concepts of object oriented programming and of course in Java these techniques are used as well. If you want to understand how a software project works getting familiar with the type hierarchy is essential. It even helps you to understand the inner workings of libraries or frameworks that you are using in your project too.

Just position the text cursor on a class and press F4 to open the type hierarchy view which will show you child and parent implementations.

Run Test: Alt+Cmd+X T

I think running unit tests are a part of understand how code works and getting familiar with an already existing non-trivial project you have just started working on. So open a unit test class and press Alt plus Cmd plus X and then T to run all the tests. I try to remember the shortcut by thinking about executing my code as a unit test – hence the X for execution and T for test.

If you are doing test driven development – which means that you are writing unit tests for relevant parts of your code probably even before the real implementation – this may help to get into the habit of just running a unit test with an even unfinished implementation just to see what happens so far.

Key bindings menu: Shift+Cmd + L

If you press Shift plus Cmd and L a context menu will appear that shows you all the key bindings that are configured in your current workspace preferences. This can be a last resort if you forgot the keyboard shortcut to a certain feature.