Compiling and Bug-fixing

You may have fiddled around with Eclipse for a while and found yourself confused as to how to compile your .java files. The truth of the matter is that Eclipse is constantly compiling your code. This on-the-fly compiling allows you to see what you might be doing wrong as you're doing it. So how do you know what's going on? How can you fix errors? Eclipse gives you a couple of ways to see the results of compilation. Note: I won't be talking about debugging, but rather simple fixes of compile-time errors.

As you're writing code, you may notice red and yellow squigly underlines appearing. Like in Microsoft Word, for instance, if you write a line of code that causes a compile error, Eclipse underlines that code with a red squigly line. If it's only a warning, the line will be yellow. Great, now what? If you hold your mouse over the erroneous code, a tooltip will eventually pop up with the error message.

In addition to mousing over, the more systematic way to error-check your code is to use the Problems view. Normally this view is pre-loaded in the Java perspective at the bottom of your screen (along with JavaDoc, Console, Declaration, etc.). Click on the Problems tab for a full listing of your coding errors. Each error listed will have a description, telling you why the compiler doesn't like it. If you double-click any error message, the editor pane will jump straight to the line of code causing that particular error, regardless of which file you're currently viewing.

One last tip for you guys: Ctrl-1 (that's a one, not an 'L') is a handy shortcut for problem fixing. If you click on a piece of broken code and hit Ctrl-1, you will get a list of suggestions for how to fix it. They're not always spot on, but most of they time they do pretty well. To let Eclipse perform one of the suggested fixes for you, select it with either the arrow keys or the mouse and press "Enter" or click.