Google

Mar 12, 2014

Top 10 Eclipse short-cut keys every Java developer using eclipse IDE must know

1. CTRL+1

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.

2. CTRL+space

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".


3. CTRL+o

You have an existing class with 15+ methods defined and want to get to a method quickly, then use CTRL+o.




4. CTRL+l

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.


1394596218303
Exception in thread "main" java.lang.NumberFormatException: null
 at java.lang.Long.parseLong(Long.java:404)
 at java.lang.Long.(Long.java:702)
 at com.writtentest11.EclipseShortCutKeys.main(EclipseShortCutKeys.java:10)

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.


7. CTRL+h

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+. In the next post, will cover CTRL+SHIFT+Top 10 Eclipse Short Cut Keys - Part 2. You will see in this Part 2, the only key that you must remember.

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home