BeanShell is a Java source interpreter, meaning that beanshell scripts are essentially pieces of Java code. BeanShell, however, also has scripting features which extend (or break, depends on how you feel) the Java language. This means, for example, that you don't have to declare the type of a variable when you use it. You can also hold different types of objects in the same variable at different times. See the BeanShell documentation for additional information.
Your code doesn't start running in a blank environment - you already have a bunch of useful variables and methods defined which you can use. The most useful is the sendCommand(String) method which simply sends the specified string to the server. You can also use various variables whose exact identity and values are determined by the type and subtype of the event that your script is running on. See also the list of the "built-in" functions and variables.
An interesting property of how your BeanShell scripts are executed is that they are stateful - you can save some state (variable values) between separate invocations of the script. Let's look at the following Chat/Personal Tell script, for example:
if (super.count == void)
super.count = 0;
else
super.count++;
if (super.count < 5)
sendCommand("tell fishbait " + super.count);
The first time the script is run, the super.count variable
doesn't exist yet, so its value is void and it gets initialized to
0. In consecutive executions, it gets incremented each time and fishbait will
receive tells with "0", "1", "2", "3" and "4" etc. (which might annoy him quite
a bit, so I recommend trying it on yourself instead ;-)). So, to "keep" a
variable between runs of the script, start its name with super..
To understand exactly what's going on, I suggest reading the beanshell tutorial at http://www.beanshell.org/manual/contents.html. In short, Jin wraps your BeanShell scripts in a method for performance reasons. The "super" scope modifier allows you to access variables global to the script. If you don't use "super", you will be accessing variables local to the method Jin wrapped your script in and the values would be gone as soon as the method finished executing.