Tuesday, August 7, 2007

Eclipse Scrapbook!

Well firstly, clear your thoughts of all notions of 'Scrapbooks' in the context of Orkut since this scrapbook, is not an evil one.

When writing Java Code one oft needs to execute a small code snippet, just to be sure of what it does so that it doesn't ruin the bigger picture. Well i used to write tiny classes for such things until i stumbled upon Eclipse's scrapbook. (Actually received via a well written email from Persistent's very nice Java Tip Of The Day mailing list ;) ).

So in eclipse, in the Java perspective, if you do a File->New->Other and then a Java->Java Run/Debug->Scrapbook Page, you'll get a plain blank page. Here, you can write these small code examples and run them.

You can Execute them,or Display or Inspect.

Execute as you would expect, will print the result in the console.

Display displays the returned value (with type) near the snippet.

And Inspect, somewhat like in the Debug perspective pops up a yellow window with the result, near the snippet.

So, if i write this :

String s = new String ("shalini");
return(s.charAt(0));

  1. Execute prints 's' in console (if there was an SOP statement in plave of RETURN)
  2. Display prints a (char) s at the end of the return statement
  3. Inspect pops up a small yellow window with the expression and its result.
The best thing is i can have n such snippets, and select and run each one independently and each one is oblivious to the presence of any other :)

And it has syntax highlighting and Autocomplete (Ctrl+Space) too!

So Scrap away!


Powered by ScribeFire.



0 comments: