We work on Eclipse every day, but still we are not aware of all the powerful features of Eclipse. It provides a lot of shortcuts and other features which can help us in coding, debugging and other tasks, eventually delivering the bug free code in a lot lesser time.
Some of them are mentioned below and yet there are a lot more J
Content Assist, Quick Fix and Class Navigation
Content assist
The content assistant allows you to get input help in an editor. It can be invoked by pressing CTRLSpace For example type syso in the editor of a Java source file and then press CTRLSpace. This will replace syso with System.out.println(""). If you have a reference to an object, for example the object person of the type Person and need to see it's methods, type person. and press CTRL+Space.
Quick Fix
Whenever Eclipse detects a problem, it will underline the problematic text in the editor. Select the underlined text and press CTRL1 to see proposals how to solve this problem. For example type myBoolean = true; If myBoolean is not yet defined, Eclipse will highlight it as an error. Select the variable and press CTRL1, Eclipse will suggest creating a field or local variable.
Quick Fix is extremely powerful. It allows you to create new local variables and fields as well as new methods and new classes. I can put try-catch statements around your exceptions. It can assign a statement to a variable and much more.
Opening a class
You can navigate between the classes in your project via the "Package Explorer" View. In addition you can open any class via positioning the cursor on the class in an editor and pressing F3. Alternatively, you can press CTRLShiftT. This will show a dialog in which you can enter the class name to open it.
Eclipse Shortcuts
Eclipse provides a lot of shortcuts to work efficiently with the IDE.
Table 1. Navigation
Shortcut
|
Description
|
Ctrl + 2 + L
|
Assign statement to new local variable
|
Ctrl + 2 + F
|
Assign statement to new field
|
Table 4. Coding
Shortcut
|
Description
|
ALT + SHIFT + R
|
Rename
|
CTRL+2, R
|
Rename locally (in file), faster then ALT + SHIFT + R
|
ALT + SHIFT + T
|
Opens the quick refactoring menu
|
Table 6. Handling the editor
Command
|
Description
|
F5
|
Goes to the next step in your program. If the next step is a method / function this command will jump into the associated code.
|
F6
|
F6 will step over the call, i.e. it will call a method / function without entering the associated code.
|
F7
|
F7 will go to the caller of the method/ function. This will leave the current code and go to the calling code.
|
F8
|
Use F8 to go to the next breakpoint. If no further breakpoint is encountered the program will run normally.
|
More Debugging Tips!!
- If you want to temporary de-activate all your breakpoints you can press the button "Skip all breakpoints". This button is visible, if you select the "Breakpoints" tab. If you press this button again, your breakpoints will be reactivated.
- After setting a breakpoint you can select the properties of the breakpoint, via right-click > Breakpoint Properties. You can define a condition that restricts when the breakpoint will become active.
- A watchpoint is a breakpoint set on a field. The debugger will stop whenever that field is read or changed.
- You can set a watchpoint by double-clicking on the left margin, next to the field declaration. In the properties of a watchpoint you can define if the execution should stop during read access (Field Access) and during write access (Field Modification).
- You can also set breakpoints which are triggered when exceptioins are thrown. To define an exception breakpoint click on the "Add Java Exception Breakpoint" icon in the "Breakpoints" View toolbar.
- A method breakpoint is defined by double-clicking in the left margin of the editor next to the method header. You can define if you want to stop the program before entering or after leaving the method.
- A Class Load Breakpoint will stop when the class is loaded. To set a class load breakpoint, right-click on a class in the Outline View and choose "Toggle Class Load Breakpoint".
For every breakpoint you can define a hit count in it's properties. The application is stopped once the breakpoint is reached the number of times defined in the hit count.
Templates
If you have to frequently type the same code / part of the document, you can create templates which can be activated via autocomplete (Ctrl + Space).
For example, assume that you are frequently creating public void name(){} methods. You could define a template which creates the method body for you.
To create a template for this, select the menu Window > Preferences > Java > Editor > Templates.
Press New. Create the template shown in the following screenshot.
cursor indicates that the cursor should be placed at this position after applying the template.
In this example the name "npm" is your keyword. Now every time you type "npm" in the Java editor and press CTRL+Space the system will allow you to replace your keyword with your template.
Automatic placement of semicolon
Eclipse can make typing more efficient by placing semicolons at the correct position in your source code.
In the Preference setting select Java > Editor > Typing. In the section "Automatically insert at correct position”, enable the "Semicolons" checkbox. You can now type a semicolon in the middle of your code and Eclipse will position it at the end of the current statement.
Enjoy Learning :)