Probably the most useful one. It activates the quick fix and generates lots of code for you. This means less typing.
Generating local variables: For example, if you have written a method call and you highlight it and press Ctrl+1, Eclipse will give you options to extract to local variable, assign to new local variable or assign to new field.
If you’ve modified a method in a abstract superclass or interface and you highlight the subclass’ name and hit Ctrl+1, you’ll get options to add unimplemented methods or make the subclass abstract.
Suppose you’ve misspelled “currentTimeMillis”, you can highlight it, press Ctrl+1 and you’ll get an option to correct the spelling.
So, Ctrl+1 is a quick fix that does the thinking for you.
This is a type assist tool. Handy for you to search for handy utility class like DateTimeUtils from the Joda library. There are myriad of libraries used in commercial Java projects, and very handy to pick a class.
Handy to pick your own classes as well if you don’t remember the exact name for your model class, but knew that it starts with “Custom”.
You have an existing class with 15+ methods defined and want to get to a method quickly, then use CTRL+o.
Say you get a stack trace in your eclipse console or in the log file as shown below, and you want to go directly to the line in your class that caused the exception, then use CTRL+l to go to the exact line number.
Exception in thread "main" java.lang.NumberFormatException: null
In the above code, the class is “EclipseShortCutKeys” and line number is 10.
So, use CTRL+SHIFT+T to select the class EclipseShortCutKeys by typing the first few characters to filter, and then once this class is selected use CTRL+l and type 10 to go to the exact line.
5. CTRL+7 or CTRL+/
You may now want to comment out the line causing the java.lang.NumberFormatException. You comment and uncomment with the toggle control keys either CTRL+7 or CTRL+/. Highlight the number of lines you want to comment or uncomment, and then press CTRL+/.
6. CTRL+mouse click
The CTRL short-cuts will not be complete without the most powerful navigation CTRL + mouse click. This brings up the contextual menu to navigate to other classes or interface. Press the CTRL key first, and then hover over the method — for example currentTimeMillis( ) on the Joda library class DateTimeUtils, util you get a contextual menu that takes you over to the actual implementation or interface.
In commercial projects, you need to navigate from service layer classes to DAO layer classes, helper classes, domain models, etc. Many different layers will collaborate with each other to implement the business use case. So, you need to rapidly move across different layer classes.
This is a generic search pop up. You can do Java search, File search, etc. Either high-light the type, method, or variable and then press CTRL+h or without highlighting to fill in the search criteria yourself. Very handy to search your selection, workspace, or working sets.
So far looked at very useful CTRL+
8. CTRL+g and CTRL+SHIFT+g
Often you need to find where a particular type or method is referenced so that you can analyze the impact of changing the referenced class or method. You also often need to find where a particular type or method is declared. Impact analysis vital in enhancing existing code base.
CTRL+G is to find declarations in workspace
Ctrl+Shift+G is to find references in workspace
9. CTRL+SHIFT+t and CTRL+SHIFT+r
Often you need to search for Java types like classes and interfaces or Java resources like spring context XML file, properties files, sql files, data files, etc. CTRL+SHIFT+t and CTRL+SHIFT+r allow you to search for types and resources respectively with wild card character like * and ?. If you do CTRL+SHIFT+r it gives you options at the bottom as to which editor you want to use to open the selected resource. You can also use these two short cuts contextually by highlighting type (E.g. class name like EclipseShortCutKeys) and then pressing the shortcut keys.
Refactoring code is a key aspect of writing quality code. For example, you might name a variable “currentTimeMillis” and use it in a number of places. But, later on decide that a better variable name would be “startCurrentTimeMillis”. If you change at one spot, you want it to be propagated to all occurrences of “currentTimeMillis”. This works for changing method and class names as well. If you change a name of a declared method, you want all the classes that referencing this method to change its values in the method invocations. This is achieved by highlighting a class, method, or a variable, and then pressing CTRL+SHIFT+R, and then change the name at the highlighted spot, and it will propagated to other locations and resources where it is used.
Do I have to remember these 10 eclipse shortcut keys?
With practice and experience, you will remember these frequently used shortcut keys. Until then, if you have to just remember 1 shortcut key, then it is CTRL+SHIFT+L, which lists all the short-cut keys in a popup.
If you press CTRL+SHIFT+L once
If you press CTRL+SHIFT+L twice