25 Jul 2009

REPL or Interactive Shell for Java

You can use the interactive shell/REPL of BeanShell to execute arbitrary Java code and see the results.

For example:
bsh % print (new java.util.Date());
Sat Jul 25 15:11:35 IST 2009
Without BeanShell, I would do something like this for trying out the same code:
// Save this in a file, say Test.java 
class Test {
  public static void main(String[] args) {
    System.out.println(new java.util.Date()); 
  }
}
Save this file, compile it using javac Test.java, fix any compilation errors, and run using java Test.  Thank you BeanShell, for saving me a lot of time and trouble!

No comments:

Post a Comment