I want to show you another selection of five keyboard shortcuts in case you are using Eclipse for Java Developers. This mix of shortcuts focuses on opening files and working with source code.
Open Resource / Open Type: Shift+Cmd R / T
The open resource or type feature is likely the most used shortcut when you navigate your source code. You either press Shift plus Cmd and R or T and start typing a part of a file you want to open. You can use the wildcard star character as a placeholder so you do not have to type the complete name.
Source – Format & Organize Imports: Shift+Cmd F / O
If you want to manually format the source code press Shift plus Cmd and F. I think it is a good habit to format the code before you save the file and adjust the format if needed.
If you are manually writing import statements it is likely that you are doing something wrong and should have a look at the autocompletion feature instead. But in the rare case that you do work on the import statements pressing Shift plus Cmd and O brings them into order.
You can automate both steps – I mean formatting and organizing imports – in the project properties under Java Editor and there is a section called “Save Actions”.
Source – Add Static Imports: Shift+Cmd M
If you do not overuse this feature static imports can make your code more readable.
Let’s say you have a static helper method like isNull from the java.util.Objects class. I think a static import makes the if statement more readable here so lets press Shift plus Cmd and M. This adds the static import for this specific method.
You can do the same thing for enum values like the employee benefit here. But as I said earlier try not to overuse static imports and make sure that it remains obvious what your code is doing.
Source – Toggle Comments: Shift+Cmd C
Commenting out code that you currently do not need is very easy. Instead of just marking everything and deleting it simply press Shift plus Cmd and C. If you press this combination again you uncomment the selected lines of code.
Source – Delete single line: Cmd D
If you have a few lines of code that you want to delete just press Cmd and D to delete the current line. By holding it or pressing it multiple times you can get rid of unwanted code lines quickly.