Programming Help by Programmer`s hub

Beanshell Scripting language

Beanshell is a small free java-like scripting language.  It runs in the Java Runtime Environment (JRE) and uses Java syntax, in addition to scripting commands and syntax. Beanshells are small and embedded so very easy to call from the other java applications and easily code dynamically at run-time or to provide extensibility in your applications. Beanshell is used to make application highly customizable by users without requiring them to compile Java classes or even to know all of the Java syntax. Beanshell is very small in size and tae very less amount pf data transfer the average size of the beanshell including full JAR is about 130K and it is expected to be reduce in the future.

Beanshell programming code example

{`
foo() {

    print("foo");

    x=5;



    bar() {

        print("bar");

    }



    return this;

}



myfoo = foo();    // prints "foo"

print( myfoo.x ); // prints "5"

myfoo.bar();      // prints "bar"

`}
...

Features of beanshell

  • source(), run() - Read a bsh script into this interpreter, or run it in a new interpreter
  • frame() - Display a GUI component in a Frame or JFrame.
  • load(), save() - Load or save serializable objects to a file.
  • cd(), cat(), dir(), pwd(), etc. - Unix-like shell commands
  • exec() - Run a native application
  • javap() - Print the methods and fields of an object, similar to the output of the Java javap command

Features of beanshell

  • Optionally typed variables.
  • Scripted methods with optionally typed arguments and return values
  • Scripted objects (method closures)
  • Scripted interfaces and event handlers.
  • Convenience syntax for working with JavaBean properties, hashtables, and primitive wrapper types.
  • Auto-allocation of variables to emulate Java properties files