-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBeanShell01.bsh
49 lines (41 loc) · 1.79 KB
/
BeanShell01.bsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* BeanShell01.bsh
* IJ BAR: https://github.com/tferr/Scripts#scripts
* *************************************************
* 1. Basics
* *************************************************
*/
// BeanShell (bsh) is "no-frills Java" and inherits all of Java
// basic syntax. You can actually mix Java code with bsh and
// the BeanShell interpreter will recognize all of it (with
// some minor subtleties, we will discuss later on). Conversely,
// converting BeanShell into Java is quite straightforward.
// Here are some basics:
// This is a comment (typically single line)
/* This is also a comment (typically multi-line) */
// BeanShell features a built-in print command that outputs to
// the Script Editor's console ("Show Output" button). It
// accepts only one argument (a string, number, object, ...).
// BTW, Note that in Java and in BeanShell, every statement
// must end in a semicolon:
print("Line 24: " + "Hello!"); // A concatenated string
// Math works as expected:
a = 1+1; // Sum
b = 2*4; // Multiplication
c = Math.pow(2,4); // Exponentiation (2^14 = 16)
print("Line 30: "+ a + "," + b + "," + c);
// Division is slightly special:
print("Line 33:" + "Integer division: 3/4=" + 3/4);
print("Line 34:" + "Float division: 3/4=" + 3.0/4);
// Note that, as in Python, variables may be dynamically typed:
d = 1;
print("Line 38: " + "d is a number: " + d);
d = "the 4th letter in the alphabet";
print("Line 40: " + "but now d is a string: " + d);
// Operators:
print("Line 43: " + "a equals b: " + (a == b) );
print("Line 44: " + "a is not equal to b: " + (a != b) );
print("Line 45: " + "a is not equal to b: " + !(a == b) );
print("Line 46: " + "a greater than b: " + (a > b) );
print("Line 47: " + "a is greater or equal to b: " + (a >= b) );
// To know more: http://www.beanshell.org/manual/contents.html