Evaluating snippets

In this section, you will evaluate Java expressions using the Java scrapbook. Java scrapbook pages allow you to experiment with Java code fragments before putting them in your program.

  1. In the File menu select New > Other > Java > Java Run/Debug > Scrapbook Page. You will be prompted for a folder destination for the page.

    Create Java Scrapbook Page wizard

  2. In the Enter or select the folder field, type or browse below to select the JUnit project root directory.
  3. In the File name field, type MyScrap
  4. Click Finish when you are done.  A scrapbook page resource is created for you with the jpage file extension.  (The jpage file extension will be added automatically if you do not enter it yourself.)  The scrapbook page opens automatically in an editor.
  5. In the editor, type System.get and then use content assist (Ctrl+Space) to complete the snippet as System.getProperties().

    Content proposals popup

  6. Select the entire line you just typed and select Display from the context menu.  You can also select Display Result of Evaluating Selected Text from the toolbar.

    Snippet editor with System.getProperties() selected showing context menu

  7. When the evaluation completes, the result of the evaluation is displayed and highlighted in the scrapbook page.
  8. You can inspect the result of an evaluation by selecting text and choosing Inspect from the context menu (or selecting Inspect Result of Evaluating Selected Text from the toolbar.)
  9. When you are finished evaluating code snippets in the scrapbook page, you can close the editor.  Save the changes in the page if you want to keep the snippets for future use.

Related concepts
Debugger

Related tasks
Creating a Java scrapbook page
Displaying the result of evaluating an expression
Inspecting the result of evaluating an expression

Related reference
New Java Scrapbook Page wizard
Java scrapbook page
Expressions view

Legal notices