Posts in the “eclipse” category

Expand "sys" to "System.err.println" with control-space

I've just recently started using Eclipse a lot, and I just typed System.err.println() one more time than I cared to. I just looked it up, and Eclipse also has templates, and one of the pre-built templates lets me type sys, then hit the [Ctrl][Spacebar] keystroke. This brings up a list of options I can choose from, one of those options being to insert the System.err.println() text in place of my sys text.

Show the method signature with control-space keystroke

Using Eclipse, if your cursor is positioned in between the parentheses of a method call, the [Control][Spacebar] keystroke will show you the signature of the method, i.e., the parameters that the method accepts. I just read where the documentation shows that you should use the [Control][Shift][Spacebar] keystroke to see method parameters, but I've found that [Control][Spacebar] works fine for me.

Let Eclipse suggest variable names with control-space keystroke

I just learned that Eclipse can automatically create (or suggest) variable names for you. The suggestions are based on the class of the object you're about to create, and any characters you've typed for the variable name so far.

For example, if I'm in a method and I type Connection, followed by a space, then press the [Control][Space] keys, Eclipse adds a variable named connection, so my line changes to Connection connection.

Eclipse can generate Java hashCode and equals methods

A nice feature of Eclipse is that you can easily generate hashCode and equals methods for your Java class using the editor. You'll really appreciate this capability when you need to create these methods whenever you're doing anything related to sorting, comparisons, comparators, etc.

How to see the source code for JVM classes in Eclipse

When using Eclipse straight out of the box, if you click on a Java-provided class, like the FileWriter class, you won't get much help when the Eclipse Class File Editor is shown. All you'll see is some binary information, with these messages at the top of the file:

Source not found
The jar file classes.jar has no source attachment.
You can attach the source by clicking the Attach Source below:

(The message really should end with "by clicking the Attach Source button below:")