Eclipse shortcuts – Make Java development easy
Jun 11th, 2009 | By admin | Category: EclipseEclipse is an widely used editor and a must used IDE for most of the Java Developers. Use of eclipse can be more fun and cool , if you know to use the eclipse shortcuts properly and effectively. What is the use of an IDE if it does the work of a notepad only(Intention is not there to blame notepad at all)? Eclipse provides a set of features in terms of key-shortcuts which make a life easy and save lots of time. Lets discuss some of the frequently used shortcuts of Eclipse. In this post , I will use the term cntrl for the keyboard control key and shft for keyboard shift key and a + sign would mean a combination os the keys.
1 . Open Resource : Key shortcuts – cntrl+shft+R
When you are working on a java project which contains plenty of resources ( files , .java , .properties , .xml etc) , you should use a cntrl+shft+R key shortcut to find the file quickly.Once you press the shortcut key combo , a dialog box should appear. Type the resource name you would like to open and get the resource displayed in the dialog itself. Double click on the displayed resource , it should get open for you. If you are not so sure about the file name you are searching for , use the regular expression like , *.java , FW*.properties etc to find the file closely related to your search. have a look at the following screen-shot,

cntrl+shft+R
2 . Open Type : Key shortcuts – cntrl+shft+T
This shortcut would help if you are looking for opening a particular type of file say , java file. Pressing this shortcut should open a dialog.Once you type a file name , the dialog shows the file name along with it’s package name. You can use regular expression as well to search the file.

cntrl+shft+T
3 . Toggle between the files : Key shortcuts – cntrl+E
When we are busy with our coding , we keep lot of files open and sometime the number of open files grows so much that it goes hidden in eclipse editor.This shortcut would help you to find the file quickly among all the open files including hidden files.Press cntrl+E , it should open a small pop-up listing all the open files.You can type the name of the file to go to the particular file.

cntrl+E
4 . Search for anything : Key shortcuts – cntrl+H
Lets assume , you have a string named FwResources declared in your java file and the same string is used in different java , properties and sql files.If you would like to search the all those place of uses , cntrl+H is the answer. It searches in whole project and list out the list of the files have the file name or the pattern.Along with file search , you can perform a java search and plug-in search as well.

cntrl+H
5 . Go to a particular line : Key shortcuts – cntrl+L
If your java file has too many lines , going to a particular line is always a problem. Often you scroll down the file and go to a particular file you are looking for.But a beautiful solution is to press cntrl+L.It opens up a dialog where you can type the line number you intended to go.

cntrl+L
6 . Search the method in a class : Key shortcuts – cntrl+O
I have seen class file having more than 50 methods . You must have seen something like that in the course of developing or maintaining a project.It’s very unlikely to remember all the method names of a class and find them easily if they are plenty in number.Use the key shortcut cntrl+O on the editor. It opens up a dialog listed all the methods in the class file.You can type the method name or a regular expression to search the method you are looking for.

cntrl+O
7 . Search the method of super class from sub class : Key shortcuts – cntrl+O+O
If you are interested to see the method from the super class , press cntrl+O+O.It opens up a dialog with all the method including super class methods.

cntrl+O+O
8 . Open a type hierarchy : Key shortcuts – cntrl+T
Pressing cntrl+T on an editor should open up the type hierarchy of the class.You can see all the super class and sub class of the class.Very handy in case you want to know the hierarchy of a class.

cntrl+T
9 .Comment a bulk of code at a time: Key shortcuts – cntrl+shft+/
If you want to comment a bulk of code at a time , don’t use // to comment each line. Select the bulk of lines which you are interest to comment at once and press the key cntrl+shft+/.
10 .Format your code: Key shortcuts – cntrl+shft+F
Eclipse has a built-in code formatter which helps you to format your code in a readable format.This formatting is very useful as code become more readable and maintainable. Select the part of the code you would like to format and press cntrl+shft+F , code would be formatted. you can create or import your own format style. Go to Winow>Preferences>Java>Code Style>Formatter . You can see the type of formatter exist, can create a new , can import a formatter for use.
11 .Find any definition and declaration: Key shortcuts – F3
How about a key press to take you to variable declaration or to a method definition. Often we find at the code where an object reference or a method call used again and again , to locate the variable declaration or to see the method definition , keep your cursor on the variable or the method and press F3 from your keyboard.Pressing the key takes you to the place where the method is defined or the variable is declared.
12 .Auto complete: Key shortcuts – cntrl+space
This is a very interesting feature and very useful. Auto complete feature in eclipse reduces the head ache of typing each and everything in your editor while coding.If you have already declared a variable or method in your class , you no need to type the full method name or the variable name to use them else where. Type first few characters and press cntrl+space , auto complete feature would take care of rest of the things. Very handy in quick development.
13 . Get all properties – dot(.) notation : Key shortcuts – . (yes , it’s just a dot)
Very tiny but very very useful. use a .(dot) after your declared reference variable , you should be able to get all the public entities of the class listed. It is not always possible to know about all the method or variable name of a class. think about a class file from a jar file where the source is not bundled and you do not have the API doc available. How would you know about the public methods / variables in the class ? Use the dot notation feature of eclipse. Type your reference to the class and press an immediate .(dot) and get all the public entities of the class.
That’s all from my side about eclipse key shortcuts. Please write comments if you liked it/disliked it and mention some more shortcuts if you know anything else. I would do another post on Making work easy in eclipse very soon. Stay tuned.
