Above is a screenshot of the basic arithmetic functions executed in Groovy. The arithmetic symbols used in Java is very similar to Groovy. A new symbol used in Groovy that is not used in Java is the dollar sign symbol. This is used in print statements. In java, when a person is coding a print line and they are concatenating words with a variable, quotations and a plus symbol is used. However, in Groovy, the whole print statement is inside quotation marks and a dollar sign is used to separate the variable with the words. This can be seen below.
The types of variables in Groovy are ints, floats, long, short, bytes, char, booleans, strings and doubles. These are similar to Java. When creating a variable in Groovy, the word def is used in front of the new variable. For example, def a = 2. However, if a person is checking to see if a is equal to 2, they would write the line, assert a==2. Lists can be made in Groovy, simply by writing, def list = [0,1,2,3,4] or any desired values inside the given list.


Does a variable that is being concatenated with a string need to be surrounded by curly brackets {} like shown in the first screenshot?
ReplyDeleteCan Groovy variables be only declared and not initialized with some value in one line of code? If so, how does Groovy know what type of variable is being declared without being initialized with some value?