BeanShell comes with a number of useful built-in commands (methods). These commands are implemented as BeanShell scripts, and are supplied in the bsh JAR file. You can make your own commands by defining new methods or adding scripts to your class path. 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 that it
insures that the ouput 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 print( )
ing of
the result of every line you type. (Turn this on if you want to see
every result.)
Here are a few other examples of BeanShell commands:
-
source()
,run( )
Read a bsh script into this interpreter, or run it in a new interpreter
-
frame( )
Display an AWT or Swing component in a frame
-
load()
,save( )
Load or save serializable objects (such as Java Beans)
-
cd()
,cat()
,dir()
,pwd( )
, etc. Unix-like shell commands
-
exec( )
Run a native application
See the BeanShell user’s manual for a full list of commands.
Get Learning Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.