Introduction To Groovy Programming


Starting with the first program printing "Hello World". There is no interactive shell available like other scripting langugages tcl, python etc.,

There are two ways to code groovy script, one is standard way as below. Following coding guidelines is important in professional development projects.

virtual-machine:~/groovy$ cat hello.groovy
class Hello {
   static void main(String[] args) {
        println('Hello World \n');
   }
}
virtual-machine:~/groovy$ groovy hello.groovy
Hello World

The other way is non standard which doesn't follow any coding structure. However this is helpful to understand the groovy commands and usage. Beginners are suggested to follow this to ensure they learn commands pretty quickly. If you observe there is no change during execution for such simple code.

virtual-machine:~/groovy$ cat hello.groovy
 println('Hello World \n');
virtual-machine:~/groovy$ groovy hello.groovy
Hello World

Some key rules to follow while writing groovy are.
1) Like other programming languages, not scripting!
2) Use semicolons for each program statement so as to distinguish the code and separate each statement.
3) Curly braces are used to start code block for void main(), conditional blocks, functions etc.,
4) Variable declaration is also similar. Use identifiers to define the variables.
This is discussed in detail going forward.

No comments:

Post a Comment

Featured Post

Introduction To Groovy Programming

Starting with the first program printing "Hello World". There is no interactive shell available like other scripting langugages t...