Above is the code and output for the Hello World program. This program is executed very similarly in java. The print command is the one that is used in Java. One difference between Groovy and Java is the lack of parentheses. In Java, this line of code would have been println("Hello World!"). However, in Groovy it is simply println "Hello World. For this line of code, a semi colon was not necessary. Semi colons are not used in Groovy to end a line of code.
The overall syntax for this program was similar to Java with a few exceptions. To define and assign a variable, the word def is used. An example would be: def name. Groovy also has assert statements which are similar to if statements and booleans in Java. The assert statements are executed if the statement is true. If the statement is not true, then the code is not executed.


Comments
Post a Comment