Quite a few times I find the need to try out small snippets of code, like string manipulation. Creating a new class for this is a pain. Fortunately Eclipse provides an easy way to do this. All you have to do is create a scrapbook (File > New > Scrapbook Page) and try out your code here.
The scrapbook has syntax highlighting and code completion. This lets you execute snippets and see the results or even inspect the results. This is a big time saver.

Related posts:
- Eclipse tip: Semantic highlighting
- Eclipse Tip: Auto-generate compilation units by pasting snippets
- JDK 1.5 Sample Code
- Blogjet
- How long is your String?
Greg
January 20, 2004 at 7:09 PM
Is there an easier way than highlighting the code you want to execute?
Vazz
January 21, 2004 at 2:05 PM
AFAIK the only way is to highlight the code you want to execute. I assume its this was as you can have a lot of different snippets in your scrapbook.
victor
February 19, 2004 at 4:32 PM
i just tried the scrapbook feature in eclipse 2.1.2, and have big problems with it. searching for help i found your page, maybe you have an idea what’s wrong:
- imported packages: java.text.* and java.util.*;
- your "string".replace() example was ok.
- this hangs in FileInputStream.open() (!?):
Calendar.getInstance().toString()
- this hangs in FileInputStream.open() (!?):
new SimpleDateFormat("dd.MM.yyyy").format(new Date());
thanks in advance for any help,
victor
victor
February 19, 2004 at 4:47 PM
ps
found out that i had to press "Resume" twice, then it went through. don’t know why. very weird.
victor
February 19, 2004 at 4:48 PM
ps
i found out that i had to press "resume" 2x, then it went through. don’t know why, have no breakpoints anywere.