Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wednesday's cool Eclipse feature of the day

 
Ed Burnette
Author
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this in the Java editor: go to a blank line and type "for" (3 letters without the quotes) and press Ctrl-Space. You'll get several options including:
for
for - iterate over array
for - iterate over array w/temporary variable
for - iterate over collection
etc...
Select the second one, iterate over array. The Java editor will create a for loop for you and take a guess at some variable names.
But that's not all. Notice the index variable is highlighted - now without clicking anywhere else start typing something and Eclipse will change the variable name in *all 3 places* it occurs. Now hit tab, and the editor will jump over to the array name and allow you to change that too.
Now to really blow your mind, these templates are completely user definable and editable. Select Window > Preferences > Java > Editor > Templates. Scroll down until you see the definition for "iterate over array" under "for" to see how this one is defined.
Enjoy!
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feet Eclipse has many this sort of hidden cards
 
Karthik Veeramani
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya i found that feature useful... Similar is this feature -
block a piece of code, right click and goto Source. Theres a cool option for surrounding with try catch block... i use this very often.
 
Karthik Veeramani
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Theres another feature i found real cool. if we start typing that our class implements a method,eclipse suggests error, saying the methods r not implemented. and as correction, it inserts all the methods in that interface into the code, saving us from typing in so many possible interface methods!
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed, Thanks for the cool tips, are these kind of tips and tricks discussed in the book or does it require a new Eclipse Hack book.
Is it matter of experience or can I go and read more about the hidden dragons inside Eclipse.
I can see how you can really speed up your development if you utilise Eclipse. I have beenusing a basic text editor with ANT until now.
- FK
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you go to: 'Window->Preferences->Java->Editor->Templates' you'll see at complete view of the 'hidden' feature.
Rene
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rene, I just had a brief look through it, its great and I guess the best thing is you can create you own features to make life easy.
- FK
 
Ed Burnette
Author
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Faisal Khan:
are these kind of tips and tricks discussed in the book...?

The template one is discussed in the book. The command shell one I found after the book was written.
 
David Gallardo
Author
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tips and tricks are presented throughout the book, where it makes sense. But the best place to get a comprehensive list is in Eclipse. Select Help->Tips and Tricks from the main menu. You can then browse through tips and trick for either the JDT, the platform or the PDE.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic