Section B.3. BeanShell Commands

B.3. BeanShell Commands

BeanShell comes with a number of useful built-in commands in the form of Java methods. These commands are implemented as BeanShell scripts, and are supplied in the bsh JAR file. You can make your own commands by defining methods in your own scripts or adding them to your classpath. See the BeanShell user's manual for more information.

One important BeanShell command is print( ), which displays values. print( ) does pretty much the same thing as System.out.println( ) except it ensures the output always goes to the command line (if you have multiple windows open). print( ) also displays some types of objects (such as arrays) more verbosely than Java would. Another very useful command is show( ), which toggles on and off automatic printing of the result of every line you type. (You can turn this on if you want to see every result value.)

Here are a few other examples of BeanShell commands:

source( ), run( )

Reads a script into this interpreter, or runs it in a new interpreter

frame( )

Displays an AWT or Swing component in a frame

load( ), save( )

Loads or saves serializable objects (such as JavaBeans)

cd( )

cat( )

dir( )

pwd( )


Unix-like shell commands

exec( )

Runs a native application

addClassPath( )

reloadClasses( )

Modifies the classpath or reload classes

javap( )

Prints a javap-style class description for the class or object specified

See the BeanShell user's manual for a full list of commands.

    Learning Java
    Learning Java
    ISBN: 0596008732
    EAN: 2147483647
    Year: 2005
    Pages: 262

    Similar book on Amazon © 2008-2017.
    If you may any questions please contact us: