Groovy Script
Groovy Script
If you want to work on groovy then you must have java in your system
DYNAMIC PROGRAMMING LANGUAGE : In dynamic programming language we can check for errors
only at runtime
Static programming : these are known and checked for correctness before running your programme
like java compile error etc
Text Editors also used for groovy but has less features
1 . Groovy Eclipse : -
Install Eclipse
Using Groovy script we can
Variables are used to store information, this information is of can be different types
examples String, int, Boolean
When we use single quotation ‘ , it will take exactly same what we can write
Data types : There are different types of data types are there Byte, Shorty,*Int,
loag,float , char etc
In above screen you can see the printing of min and max values of Byte and Short
Operators ::
Operators in are symbols that tell the compiler to perform some specific operations
1 .arithmetic operators
2. unary operators
1. Conditional statements
2. Looping
3. Exception handling
Conditional statements ::
These are also called as Decision making statements
1 . if –else
2 . Switch- case
1 . if – else :
You have to define the case in curly braces only otherwise it will give an error
Loops ::
There are three types of loops are there
1 . for
2 . for in
3 . while
And three keywords we use in these loops
1 . for :
We will use any number of conditions in for loop , for every condition it will chwck and give
the output
Here in above screen it will check i=1 then check if it it is less than 5 or not if 2 nd condition
satisfies then it will go to 3rd condition and increments the value of i and check the next
condition , this loop will continue upto condition lapses
For other condition and keywords the syntax will be like below
In STEP (10 ,2) means that it will be incremented every 2 number upto 10 i.e. 1,3,5,9
For WHILE loop the syntax should be like below
Exception handling ::
In exception handling we have three methods
1 Try-catch
2 Try-catch-finally
3 Try-finally
.
Strings ::
In single quoted string we can not refer a variable , this property is called intertpolation
Whwenever you want to use multiple lines then we will use triple multicoated ones i.e triple
double qupoted or triple single quoted
If we want to print the position of the index character then we can use the number in square
brackets i.e. for ex. [2]. If you ewant to count from the reverse i.e. from right to left then we
will use [-2] and also we can use .IndexOf(char) to findout the position of that character
We will use println name[0..2] then it will print the latters from 0 to 2 i.e Rag in above name
We can also print from the right and also from substring
Methods ::
It is a block of code that can take parameters, refer variables, return values and can be
passed as a parameter in a method
First we define the closure then you have to call it like below i.e.your closure name.call
Lists : :
List is a structure to store collection of data types
It is an ordered collection of data
Syntax : [ Obj1 , Obj2 , Obj3 ……], this Obj is of any data type , it can be int or string or char or
floating type there can be nested list also
We can see different types of functions below screens and we caln also clone the entire map
Ranges ::
Example 1…10 , a…z . 10…1 and we can use assert whether the statement is
correct or not if it is correct it will not throw any exception , if it is incorrect then
it will throw an exception
Ranges are of instanceof java.util.List
For this error copy the path and goto cmd and give that path