Eclipse Shortcut Keys for Smart Developers


Eclipse shortcut for java development

Most of the software developer use integrated development environment (IDE) to write code. A Java IDE (Integrated Development Environment) is a software application which enables users to more easily write and debug Java programs. Many IDE’s provide features like syntax highlighting and code completion, which help the user to code more easily. More specifically Eclipse is leading development environment for java with a market share of 50 % in IDE space. Here we would look at the basics of eclipse IDE and available smart keys(shortcuts) available in Eclipse . Eclipse download is available in Eclipse.org

Eclipse Java JDK

To begin the Eclipse, double-click the eclipse.exe (Microsoft Windows) or eclipse (Linux / Mac) file in the directory.The Eclipse system prompts you for a workspace. The workspace is the place in your file system where Eclipse keeps its preferences and other resources required for running the java application.The workspace is the physical location (file path) you are storing certain meta-data and (optional) your development artifacts. Your projects, source files, images and other artifacts can be stored inside or outside your workspace.

Different views available of eclipse:

To look at all the files in the project: The Package Explorer view allows you to view the structure of your projects and the specific file in the project by double click on the file.It is also used to change the structure of your project. For example, you can rename files or move files and folders via drag and drop. A right-click on a file or folder shows you the available options.
To know all the issues at one place : If you want to see all the issues and warning in single place, go to problem view of the project. The Problems view shows errors and warning messages. Before run the program, verify in problems view that there is no issues in the project. To view the problems in your project, you can use the Problems view which is part of the standard Java perspective.
The Debug View allows you to manage the debugging or running of a program in the workbench. It displays the stack frame for the suspended threads for each target you are debugging. Each thread in your program appears as a node in the tree. It displays the process for each target you are running.

Search – Find a Java file in Eclipse:

If we forget the java file location, we can find easily by the just type file name in find type window by pressing “Ctrl +Shift +T”. It allows the wildcard search as well such as “*Bean.java” to display all the class names ends with “Bean” in the project.

Search – Find a Property file in Eclipse:

Created the property files or configuration files in the project and missed the folder location, eclipse can search for you by Find resource smart key “Ctrl + Shift + R”. Just enter the resource file name or wildcard search terms, eclipse would show the resource file location.

Analysis – Parent of the Class:

Have child class and want to see all the all the parents of the class? Just enter “Ctrl+ T”. It will show “Type Hierarchy”, all the parents’ classes of the class.

 

Usability – Search a String in all the files:

Thinking to see how many places we used “System.out.println” in the project? Do not go over all the files and count. Eclipse gives smart key option “Ctrl + H”. In the search window, give your keyword to search. It would list all the files and location of the searched term in the project.

 

Usability – Get a assistance from Eclipse:

Do you know eclipse can fix the issue for you in the code. If the code has some problem or missed to import the package file? Don’t search the package name of the class in Google. Just enter Ctrl +1 in the problematic line in the code. Eclipse would help you to fix the issue by showing all the possible code grammatical issues. How smart the eclipse is!!!

Refactoring – Cleanup Unused import statements:

Copied package import statements from other java file and all the unused package names shows “Warning” in the java code? Do not worry. Just enter “Ctrl + shift + O”. Eclipse would remove all the unused package name in the import list and all the package warning will be gone.

 

Readability – Indentation of Method:

– Written the complex method with 3 “while” loop, 2 “for” loop, and 4 “if” statement. The method works properly by giving expected output. But forgot to format 20 curly braces in the method. Indentation would be painful in the method has 20 curly braces. Eclipse IDE makes it simple by smart key “Ctrl + I”.

Documenting – Commenting out line:

While writing the code, documenting one line comment is necessary for complex business logic or decision algorithm at places in the code. Eclipse encourages to write comment for code and it gives smart key “Ctrl + /” for single line comment. Write a comment and just key “Ctrl + /” . That’s all. Your code is commented.

Usability – Smart suggestion of possible values:

Do not type full method, class or variable. Just type few character and enter “Ctrl + Space “. It will show all the possible values in that place. Eclipse intelligence helps to suggest the appropriate values. For example, Just type ma and press Ctrl + Space, you will get “public static void main(String[] s)” the signature of the main method. Type Sysout and press “Ctrl + space “ to get “System.out.println”.

 

Refactoring – Split the method:

The first rule of methods is that they should be small. The second rule of methods is that they should be smaller than that. Methods should not be 100 lines long. Methods should hardly ever be 20 lines long.

Sometimes a method was written with more than 100 lines. Refactoring the code is nightmare. It is hard to split the method to smaller method if many variables involved in the method. Eclipse helps us to split the method by selecting the block of the code in the method and enter “ALT+ Shift +M”. Creates a new method containing the statements or expression currently selected and replaces the selection with a reference to the new method. This feature is useful for cleaning up lengthy, cluttered, or overly-complicated methods.

Formatting – Wrap the coding:

The readability of the code is important. The single line code should not go beyond 130 characters. If code has lengthy lines and formatting each line one-by-one would be tough task. Select the code and enter “Ctrl+Shift+F”. It would format all code that is format tabs/whitespaces and also divide code lines in a way that it is visible without horizontal scroll. and it would increase readability of the code.

Useful smart keys in Eclipse

F3 | Goto declaration
Alt Shift M | Extract method
Ctrl Shift O | Organize Imports
Alt Shift C | Change method signature
Ctrl G | Find declarations in workspace
Ctrl F3 | Outline of current cursor position
Ctrl Shift P | Navigate to matching bracket/brace
Ctrl Shift Arrow| Jump between methods up or down
Ctrl Shift G | Find references in workspace
Ctrl Shift U | Find references in file
Ctrl O | Outline of current source
Ctrl Alt H | Open call hierarchy
Ctrl T | Popup type hierarchy
Alt Shift L | Extract local
Ctrl Shift F | Reformat

You may also like