There may be times you have a fragment of Java code that you want to try out before adding it to a class or project in the workspace. Along with being a good place to keep notes and lists of ideas, the Scrapbook also provides a flexible environment for testing and experimenting with any piece of Java code. Contents of Scrapbook pages are saved to files, not to the repository.
To open the Scrapbook, select Scrapbook from the Window menu of any IDE window.
Running Code Fragments in the Scrapbook
To run a code fragment in the Scrapbook:
While the page is running the code fragment, its page symbol changes to indicate that it is busy. No other code can be run from that page while it is busy.
Resetting a Busy Page
To stop a running code fragment:
When a page is reset, all threads started from the page are terminated, and all classes in the code are uninitialized. The compilation context and the text on the page do not change.
Changing the Compilation Context
When the code fragment runs, the IDE assumes it belongs to a particular class and
package that exists within the workspace. This class provides a compilation
context for the fragment, which determines what other program elements are inherited
by and accessible to the fragment. Each Scrapbook page has one compilation context,
which is by default java.lang.Object.
To select another compilation context:
The information line at the bottom of the Scrapbook page indicates the compilation context for the page. All code fragments run from the page will use this compilation context.
Inspecting and Debugging Code Fragments
Just as you can inspect variables for code in the workspace, you can also inspect
variable values in code fragments in the Scrapbook. To inspect a code fragment in
the scrapbook, select the code that you want to inspect, and then click the Inspect
button .
If the selected code returns a result that can be inspected, an Inspector window is launched. If the selected code does not return a result that can be inspected, the following message is displayed on the page:
No explicit return value.
Similarly, you can debug the code fragment by using the integrated debugger. To
launch the debugger, select the code you want to debug, and then click the Debug
button .
Example: Running Code in the Scrapbook
Organizing Your Ideas in the Scrapbook
Debugging During the Development Cycle with the Integrated Debugger