Cool Tips and Tricks

Eclipse is full of little features put there to make your life easier. Many of them are kind of trivial by themselves, but I find myself using them frequently. That said, this list barely scrapes the surface. If you really want to dig in, check out the built in help files (starting with the Help menu), or check out O'Reilly's Eclipse Pocket Reference (or something like that). Try not to use these as crutches, but rather to help you be more efficient. These tricks are all about saving time while you work. You'd be amazed at the difference that things like Code Assist, keyboard shortcuts, auto-compilation, etc. will make in the time it takes for you to code something up.

Can't remember keyboard shortcuts?

Viewing the keyboard shorcut window

In Eclipse you really only have to remember one keyboard shortcut: Ctrl-Shift-L. This shortcut will pop up a list of every keyboard binding in the program in an alphabetized list. Sweet! Why care about keyboard shortcuts? If you don't know, you haven't been programming long enough. You will begin to hate your mouse (it's slow!), and every chance you get not to use it will be a blessing.

Code Assist

Code Assist in action

Lucky for you, I've made a whole page dedicated to this alone. Check out using auto-complete (code assist).

Suggestions For Errors

Using error suggestions of Ctrl-1

I touched on this in compiling and bug-fixing, but Eclipse has a feature that suggests ways to fix compile errors and warnings. If you have some sort of error or warning, click on the broken code and hit Ctrl-1 (and again that's a number one, not an 'L'). A list of possible options will pop up. They're not always the best, but often times they work pretty well (especially for things like forgotten imports). Don't use this blindly, though.

Curious about a definition?

This is one of my all-time favorite keyboard shortcuts when programming code that works together with other code you haven't written. If you want to see where a particular method, class, data field, etc. is defined, simply click on it and press F3. It's necessary to have access to its source, however, so it won't work with pre-compiled libraries. You can use it with the Java libraries if you have the Java source on hand.

Never get docked for format-related style again

Before and after auto-formatting

This is my way of saying that anybody who tries to get away with poor formatting on one of their assignments will be granted no mercy. Eclipse has two features that will alleviate whatever formatting or indentation woes you may have. If you select a block of code (or alternatively, select all), and hit Ctrl-I, you will be pleasantly surprised to see the block indented properly. There is another command which is even more powerful, Ctrl-Shift-F, which will go as far as to format your code to the Java standard spec. This includes spacing, use of new lines, indentation, etc. Both of these commands are also accessible from the Source menu.

Cleaning up your code

The Eclipse Clean Up menu

I'm only going to throw this out there. You can play with it if you want. Eclipse has a feature found under Source > Clean Up... that will actually streamline your code to reduce redundancy, eliminate unused or meaningless code, and make it more elegant. It's only so powerful, but useful nonetheless. However, as a programmer, your goal is to run Clean Up and have nothing change due to your code already being "perfect." This is not some unattainable dream, but rather something you should be capable of now.

Track your To-Dos

The Eclipse Tasks view

Inevitably, there are things that arise while you're coding away that you want to remember but can't address in the moment. One convention in industry is to put comments in your code that say "// TODO: insert task here" to record such needs. Eclipse makes your life that tiny bit easier by searching your project for all "// TODO:..." comments and keeping track of them in one window.

The Tasks view shows you a nice itemized list of all the TODOs you've left throughout your code, and what file each one lies in. Most importantly, it allows you to jump to any one of them by double-clicking, regardless of the currently active file.