One of the most undervalued and forgotten features of Eclipse is the scrapbook page, which allows to execute Java expressions without having to create a new Java program. This is a neat way to quickly test an existing class or evaluate a code snippet.
To create a scrapbook page choose File -> New -> Other -> Java -> Java Run/Debug -> Scrapbook Page, choose a name and destination folder and that’s it.
Now there’s an empty page where regular Java expressions can be written and evaluated, to do so just select the expression and choose one of the availabe operations (either in the toolbar now available or the context menu).
|
Try this: write new java.util.Date(), selecting the text and clicking Display or Inspect.
Display will evaluate the expression and print the result directly on the scrapbook, basically the return of a toString() applied to that object or the return value of the selected Java method.
If the information displayed is not enough, there’s the Inspect feature (just like the example on the right) which shows an debug window with all the details of the selected object, and all this happens without executing any code or switching to the Debug perspective.
|
|
 |
|
To evaluate code snippets there’s the Execute feature, this will execute a block of code, just like in a regular java program. A quick way to try this is to send something to the standard output: just write System.out.println("Scrapbook example"), select the text and hit Run, this should print something on the Console window (just like the example on the right).
Because a scrapbook page is created within a Java project, all the classpath libraries and projects references can be used; another nice feature is having the code assist, just like in a regular Java editor page. In a scrapbook page the class names fully qualified, there’s no, this isn’t much of a problem because the code completion handles this nicely, but if you’re working with unusually large class names you can check the Set Imports option, this will open new window where all the import expressions can be inserted (just the import section of a regular class file).
A scrapbook page is not as fully featured as the Java editor, there’s no outline and the code assist is somehow limited, but is not meant to that way; the idea is working with just a few lines, and this where the scrapbook page can be usefull: to quickly test Java expressions and code blocks present in a project in this kind of sandbox.
|
|
 |
Technorati Tags: Eclipse
Related Posts (generated)