View RSS Feed

My Java Tips

Scrapbook in Eclipse

Rate this Entry
by , 05-24-2011 at 01:23 PM (4413 Views)
Consider the following scenario: you are working on a project with client specific APIs .You need to test some API methods before you put them in your real code. For that, you might consider a separate test workspace or defining a new test class in your running workspace. What about scrapbook page? Ever heard of it?

Eclipse provide scrapbook pages to test write test code for experimental purposes. It is easier to use a Java scrapbook page than create a new class. A scrapbook page might contain random snippets of code that you can execute at any time without a context.

A scrapbook page has extension .jpage. To create a new scrapbook file, simply create a file with a .jpage extension. You can also use the New Scrapbook Page wizard as shown below:

Name:  scapbook.jpg
Views: 748
Size:  18.0 KB

Now you have created the scrapbook page lets write some code in it and see how it works.

Write Java code in scrapbook page. Code assistant is also available. Use it if required. To execute the code, highlight the code, right click it and select execute.

There are three ways to execute your code:

  • Execute the selected code and place the returned result in an inspect popup
  • Execute the selected code and place the String result right in the scrapbook page
  • Execute the selected code (and ignore any returned result)


You can find these actions in the scrapbook page's context menu.

Examples:

Java Code:
System.out.println(new Date());
Output:

Java Code:
Date cannot be resolved to a type
Java Code:
System.out.println(new java.util.Date());
Output:

Java Code:
Sun Oct 05 10:23:44 CEST 2008

Submit "Scrapbook in Eclipse" to Facebook Submit "Scrapbook in Eclipse" to Digg Submit "Scrapbook in Eclipse" to del.icio.us Submit "Scrapbook in Eclipse" to StumbleUpon Submit "Scrapbook in Eclipse" to Google

Tags: scrapbook Add / Edit Tags
Categories
Eclipse

Comments