Eclipse run java code easily

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. 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.

Eclipse Scrapbook


1 Comment Leave a Comment

Lissy [ Quote ]

neat!

December 13th, 2008 at 10:09 am

Leave a Comment Name, email and comment are required.
Email will never be displayed.

Leave a Comment
  1. :biggrin: :blank: :blush: :bored: :confused: :cool: :down: :evil: :frown: :grin: :grr: :laidback: :left: :mad: :right: :sad: :secret: :shock: :smile: :stress: :tongue: :up: :wink: :yawn: :cute: :dead: :film: :floppy: :glasses: :grumpy: :headphones: :heart: :lightbulb: :ouch: :tv: :upsidedown: :vodka: :yell: :yuck: :yummy: