Wednesday, 25 January 2017

Write your first Groovy Program

Write your first Groovy Program

If you remember we already discussed in my previous post about adding Groovy to your resume. Adding new skills will always help and increase your chance of getting your dream job.

Before everything you should have hands on experience on groovy programming. Lets see how to write a simple groovy program. As a newbie for groovy , you should start a basic hello world program.

Before start your first groovy program , you should make sure you have groovy installed in your machine (Desktop/Laptop). I am using Linux (ubuntu) here to demonstrate this example.

You can check in your terminals and I have already installed Groovy. Below command I have used to check whether groovy is installed and what version of groovy I am using.

root@jdg-HP-ProBook-6450b:~/grovytest$ type groovy
groovy is hashed (/usr/bin/groovy)
root@jdg-HP-ProBook-6450b:~/grovytest$ groovy -version
Groovy Version: 1.8.6 JVM: 1.7.0_121 Vendor: Oracle Corporation OS: Linux

Now, we can write our first groovy program. Usually groovy files are saved with extension xxx.groovy. Groovy program doesn't required semicolon (;) to close like java.This is very simple and reduce the developer effort of coding.

Open vi editor or text pad. Lets start writing your first program. 

Below is a Sample groovy program :-


println "Say Hello to Groovy"

Now save this file with extension .groovy. In this example I have given the file name as HelloWorld.groovy.

Now you need to execute this .groovy file using below command  on terminal and check the output. 

root@jdg-HP-ProBook-6450b:~/grovytest$ groovy HelloWorld.groovy
Say Hello to Groovy

Now you can see the output I have highlighted in color. This is a simple groovy program. Find more programs on my subsequent posts.

Hope this will help you!!!

Follow for more details on Google+ and @Facebook!!!

Find More :-


No comments:

Post a Comment