We can even make some function in BeanShell
add(a,b)
{sum = a+b;
print(sum);
}
Then we call this function any number of time we want
add(7,5);
add(5,10);
As we have not defined the type of a and b so func is a untyped function.So it can accept any type of arguments when it is called be it integers,double or String etc.
add("Hi", "there");
Typed func-Which accept arguments of a particular data type and return data of a particular type like String.
String conc(String a,String b){
return a.concat(b);
}
Then we can call it
print(conc("A","D"));
We can even write a function in an external file and call the function from the same file.
Then we can save this function as with .bsh extension in double quotes.
Void helloworld(){
System.out.println(“Hell0”)
}
helloworld();
Save it as “externalbsh.bsh”
Then make a new Bean Shell Sampler in our project and instead of typig something in script we choose the external file and we run it.