Eclipse has a scrapbook function that allows you to run Java code on the fly. Sometimes you just want to test out a simple piece of code without having to create another Java class, execute it in the main method or create a junit to test it out.
For example, today I wanted to make sure I remember integer division in Java correctly. So I simply just want to execute the following piece of code.
int a = 10; int b = 8; int c = 17; System.out.println(a / b); System.out.println(c / b);
In order to do that, create a new Scrapbook page in your project.
- Right click project -> New -> Other… (or CTRL+N)
- Search “scrapbook”
- Create a new scrapbook page. I just called mine blah.jpage.
- Then paste the code in there. Highlight the code, right click and select execute or ctrl+U. The results of your execution will then show up in the console. That comes in pretty handy sometimes.
neat!