Posted by:Jyoti Trehan May 26th, 2014

The History

Java IDEs (Interactive Development Environments) or RAD tooling (Rapid Application Development) has evolved in slightly different ways than IDEs for other languages and platforms. To begin with, IBM owned Eclipse and they gradually open sourced it. Now, there are tens of strategic developer member companies and hundreds of add-in provider companies that are adding to plugins and feature set. Eclipse is one incredible produce of open source revolution and showcases what open sourcing / crowd sourcing can do to the world of software product developmentand to the mankind at large.

Here are some simple Eclipse keyboard shortcuts – your chance to refresh your memory or learn something new!

1)    Alt + Shift + R – Rename

This beautiful keyboard shortcut lets you rename any method or class or variable or attribute anywhere in the source code. It takes on the heavy lifting task of changing the name all over the codebase on itself. It is fairly obscure and less used in spite of being the best shortcut for beautifying the code.

2)    Alt + Shift + M – Extract Method

This keyboard shortcut lets you rename any method or class or variable or attribute anywhere in the source code and takes care of the burden of changing all over the codebase on itself. It is fairly obscure and less used in spite of it being the best shortcut for code refactoring which is one of tenets of Agile methodology.  Remember the good old rule of coding wherein a functions’ body should not exceed one page full or your monitor screen size. Now sticking to that rule is a breeze. All you need to do is select a bunch of lines in a function with big body and press this shortcut. It will ask for a name for the new method that you want it to create in order to reduce the big fat body of your current function. It figures out the input/ output parameters by itself.

3)    Alt + Shift + L – Extract Local Variable

Can you remember having run into clutter because of too many small little string or number manipulation functions being called in a cascaded fashion on a single line and ended the line with a bunch of closing parenthesis. If yes and you felt the urge to make the code simpler, readable and maintainable but didn’t want to go through the nightmare of deciphering which parenthesis belongs to the end of which function. With this shortcut, just select a function call and press this shortcut and pick a name for the local variable that will be used to create a new line of code right above the spaghetti you are trying to get rid of.

4)    Ctrl + Shift + O – Optimize Imports

Every time you include a new library jar file or grab a bunch ofJava code from another source, you run into the issue of classes not found and hence code not being compilable. You can use this shortcut to make Eclipse resolve those classes by itself. Also, if you have inadvertently imported too many classes than what you needed, this shortcut will also fix that.

5)    Ctrl + F11, F11 – Run, Debug

This is a handy-dandy way of running and debugging your last run configuration especially when you are in the middle of an intense debugging session and not interested in being distracted by unrelated IDE nuances and features. Every time you stop the app server or a running program and make minor code change and quickly want to see the effects of it, just press F11 and you are all set to see how your change worked out.

6)    Ctrl + h – Search

This one pops-up the elaborate Eclipse version of “find in files” type search that any text editor would provide. The dialog has got several tabs and by default it shows “Java Search” tab. Javasearch tab is really helpful if you are looking for function or attribute with a specific name. Instead of showing all the results for a keyword, you can narrow it down to Constructor, Field, Type, Method, Package etc. To make it even better, Eclipse has got a notion “scope” of search and user can pick between Workspace, Enclosing Projects, Selected Resources and Working Set. Working Set is a user defined set so it could be anything. Working Set really comes handy if you have 10 projects or so and you want to avoid searching all of them and instead search in 2 out of the 10 projects.

7)    F3 – Go to declaration

This is one extremely powerful though unassuming and very rarely used keyboard shortcut amongst the new users of Eclipse. This takes you to declaration of a class, method, attribute, local variable or anything visible inside Eclipse. Use it in conjunction with “Package” explorer in the left pane and it will quite awesomely even jump into source codes of third party libraries being used in the project assuming they are available. This way you can be sure about which library and, more importantly, which version of that library you are using.

8)    Ctrl + Shift + R  – Open Resource

This shortcut pops up a dialog with a textbox. You can type first few characters of the file you are looking for and all files starting with that name will show up. If you are comfortable with regular expressions then you can use those as well and narrow your search when better. See below how it shows all files starting with Guest just on typing “gue”.

java_eclipse_keyboard_shortcut_1

You can further narrow down search to only xml files by typing the regular expression gue*.xml. See below:

java_eclipse_keyboard_shortcut_2

9)    Ctrl + O – Outline view

If you are a very real estate conscious developer like me during coding and don’t like being distracted by many views being open, this one is for you. You can keep Outline view closed at all times. This shortcut will popup outline view of Eclipse for the current class. It also displays a textbox on the top so that you can narrow down and jump to the function you are looking for.

java_eclipse_keyboard_shortcut_3

See how the outline view will narrow down to only one function on typing first few characters of function name like ‘list’. Now you can jump to this function in the class by hitting Enter key or clicking it.

java_eclipse_keyboard_shortcut_4

10)    Ctrl + t  – Supertype hierarchy

Another one of my favorites is the “Supertype hierarchy” which helps you navigate to implementation of an interface. Press Ctrl+t and click on specific implementation(s) of any method declaration in an Interface.

java_eclipse_keyboard_shortcut_5

11)    Ctrl + Alt + Arrow up/Arrow down – Quick copy and paste

Last but not the least, this shortcut makes a copy of the selected lines immediately before or after the last first or last line respectively. You can even partially select lines. This is one simple Eclipse keyboard shortcut that you will use several times a day. I’ve observed new developers not using it and instead doing the following 4 steps to accomplish the same results which is an overkill to say the least.

  • Select lines to be copied over (select complete lines otherwise partial line will get copied over)
  • Hit Ctrl+C
  • Hit right or down arrow
  • Hit Ctrl+V

NOTE: If Windows OS level shortcuts are holding on to this key combination (i.e. Ctrl+Alt+Arrow Up/Down) for flipping monitor up and down, then disable Windows shortcuts by doing the following:

Right-click on Desktop and select Graphics options > hotkeys > Disable

Life is too short to do trivial editing through roundabout ways. Shortcuts really help you do more without having to squint at the screen at all times for editing code. They are an important part of usability of an IDE. Using mouse for selecting toolbar buttons or menu items is old school and too much material handling cost as a mechanical engineer would like to put it.

So what are your favorite Eclipse keyboard shortcuts? Please share.

Take charge of your enterprise app strategy ! Download this eBook with the 10 best practices and get started

Leave a Reply

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