blob: 32d7640e19d1c6f72fcb0369a93a061e2f0f828e [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2001, 2011. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
<title> Evaluating snippets </title>
</head>
<body>
<h1> Evaluating snippets </h1>
<p> 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. </p>
<ol>
<li> In the File menu select <STRONG>New &gt; Other &gt; Java &gt;
Java Run/Debug &gt; Scrapbook Page</STRONG>. You will be prompted for a folder
destination for the page. <p> <img src="images/wiz_new_scrap.png" alt="Create Java Scrapbook Page wizard">
</p></li>
<li> In the <strong>Enter or select the folder</strong> field, type or browse below
to select the <em>JUnit</em> project root directory. </li>
<li> In the <strong>File name</strong> field, type <em>MyScrap</em>.&nbsp; </li>
<li>
Click <strong>Finish</strong> when you are done.&nbsp; A scrapbook page
resource is created for you with the <em>jpage</em> file extension.&nbsp; (The <em>jpage
</em>file extension will be added automatically if you do not enter it yourself.)&nbsp;
The scrapbook page opens automatically in an editor.
</li>
<li> In the editor, type <code>System.get</code> and then use content assist (<kbd>Ctrl+Space</kbd>)
to complete the snippet as <code>System.getProperties()</code>.
<p> <img src="images/editor_myscrap_sysytem_get.png" alt="Content proposals popup"> </p>
</li>
<li> Select the entire line you just typed and select <strong>Display</strong>
from the context menu.&nbsp; You can also select <strong>Display Result of
Evaluating Selected Text</strong> from the toolbar.
<p> <img src="images/editor_myscrap_display.png" alt="Snippet editor with System.getProperties() selected showing context menu">
</p>
</li>
<li> When the evaluation completes, the result of the evaluation is displayed
and highlighted
in the scrapbook page. </li>
<li> You can inspect the result of an evaluation by selecting text and
choosing <strong>Inspect</strong> from the context menu (or selecting <strong>Inspect
Result of Evaluating Selected Text</strong> from the toolbar.) </li>
<li> When you are finished evaluating code snippets in the scrapbook page, you
can close the editor.&nbsp; Save the changes in the page if you want to keep
the snippets for future use. </li>
</ol>
<P class="nav_footer" id="nav_footer">Next Section: <A href="qs-Browsing.htm">Using the Java browsing perspective</A>
</P>
<p><img src="../images/ngrelc.png" alt="Related concepts" ><br>
<a href="../concepts/cdebugger.htm">Debugger</a></p>
<p><img src="../images/ngrelt.png" alt="Related tasks" ><br>
<a href="../tasks/task-create_scrapbook_page.htm">Creating a Java scrapbook page</a><br>
<a href="../tasks/task-display_evaluation_result.htm">Displaying the result of evaluating an
expression</a><br>
<a href="../tasks/task-inspect_evaluation_result.htm">Inspecting the result of evaluating an
expression</a></p>
<p><img src="../images/ngrelr.png" alt="Related reference" ><br>
<a href="../reference/ref-wizard-scrapbook.htm">New Java Scrapbook Page wizard</a><br>
<a href="../reference/views/ref-view-scrapbook.htm">Java scrapbook page</a><br>
<a href="../reference/views/expressions/ref-expressions_view.htm">Expressions view</a></p>
<p><a href="../notices.html"><img src="../cpy.png" alt="Legal notices" ></a>
</p>
</body>
</html>