You are on page 1of 8

How to work with IDE( integrated development environment)

groovy console
=================================

getText
=======
=>It is used to get the text from the file
=>It will read complete file as a single string

readLines
========
=>It is used to read the complete file as a array

Regular expressions
===================
=>It is used to search and display the data
=>text manipulation
=>pattern matching

Binding operator
==================
=~ It is true, if the given pattern found

Wild card character or meta character or anchors


================================================

+
===
It matches 1 or more occurences of preceding character

ab+c

b is preceding character

abc
abbbbbbbc
ab7c Not accept
abbhc Not accept

abcd
[-]
====

[a-z] lowecase
[A-Z] uppercase
[0-9] digit
[a-zA-Z] alphabet
[a-zA-Z0-9] alphanumeric or \w

a[0-9]c

a0c
a1c

[^a-z] non-lowecase
[^A-Z] non-uppercase
[^0-9] non-digit
[^a-zA-Z] non-alphabet
[^a-zA-Z0-9] non-alphanumeric or special character

\s whitespace(space, newline , tabspace)

How to search line contains only 3 words


==========================================
\w+\s\w+\s\w+

{m}
=====
It matches exact m occurences of preceding character

ab{3}c

abbbc

{m,n}
=====
It matches min m occurences and max n occurences of preceding character

ab{2,4}c

abbc
abbbc
abbbbc
abc Not accept
{m,}
=====
It matches min m occurences and no limit for max

ab{3,}c

abbc Not accept

abbbc
abbbbbbbbbbbbbbbbbc

Name validation
===============
=>Name should contains min of 2 character
=>Name should contains only alphabet

[a-zA-Z]{2,}

Mobile number validation


=========================
=>Mobile number contains 10 digit number
=>Number should start with 6 or 7 or 8 or 9

[6-9][0-9]{9}

Line pattern
=================

^ ->Lines start with

$ ->Lines ends with

Functions and Modules


=======================
2pm to 3pm

===========
4.15pm to 6pm -> OOP and exception handle
================
Functions or procedures or sub-routines
==========================================
=>Re-usability
=>reduces the code length

1)Built in functions
2)user defined functions

def
======
is a keyword to define a function

syntax
======
//function definition

def functionname() {
----
-----
-----
}

//functioncall

functionname()

with arguments
===============
//function definition

def functionname(arg1,arg2,arg3..) {
----
-----
-----
}

//functioncall

functionname(value1,value2,value2..)
scope of variables
====================
global variables
=>The global variables we can access anywhere in the script

local variables
===============
=>Local variables we can access only with inthat function

def ->is used to make any variable as local

return
========
=>It is used to return to the function call

Modules
========
=>Module is a collection of function
=>Module is a another groovy script

import is keyword to import module properties

syntax
=======
import modulename
modulename.propertyname()

How to create alias for the modulename

modulename as aliasname

exception handling
===================
1)syntax error
2)runtime error

1) try.. catch

2)try.. multiple catch blocks


3)try..multiple catch blocks with finally

1) try.. catch
--------------
try {
----
----
}
catch(Exception arg)
{
---
---
}
---

2)try.. catch except blocks

======================================
OOP
===

class
=====
=>class is a blueprint or template or prototype to create an objects

objects
=======
=>objects is instance of the class

class classname
{
---
----
methods
constructors
-----
}

object=new classname() ->Object creation statement

Functions
=============
=>Functions we can create outside of the class
=>we can call the function with functionname directly

Methods
===========
=>Methods we create inside of the class
=>methods we can call with one reference object
=>with respective of one object one method can execute N number of times

constructors
============
=>constructor is a special method
=>constructor will execute at the time of object creation
=>with respective of one object one constructor will execute only once

//bankname="SBI"

//Bankapp
//withdraw
//deposit
//balenq
//customerdetails

//cusname,custaccnum,bal,add

class variables
================
=>static variables
=>instance variables
=>local variable

Inheritance
===========
=>Accessing the properties of one class into another class

class x ->parent class or base class or super class

class y ->child class or derived class or sub class

extends is a keyword to get the properties from one class to another class

poly morphism
===============
poly ->many
morphism -> forms

1)Methods over loading


2)Methods over riding

1)Methods over loading


========================
=>with in the same class, if you write multiple methods with same name with different
number of arguments is called method over loading

2)Methods over riding


=======================
=>creating multiple methods with same name one in super class and other one in subclass

super.propertyname()

super is keyword to access parent class property if incase if we are using same propertyname in child
class.

You might also like