Professional Documents
Culture Documents
Day 3 Notesgroovy
Day 3 Notesgroovy
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
+
===
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
{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
abbbc
abbbbbbbbbbbbbbbbbc
Name validation
===============
=>Name should contains min of 2 character
=>Name should contains only alphabet
[a-zA-Z]{2,}
[6-9][0-9]{9}
Line pattern
=================
===========
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
return
========
=>It is used to return to the function call
Modules
========
=>Module is a collection of function
=>Module is a another groovy script
syntax
=======
import modulename
modulename.propertyname()
modulename as aliasname
exception handling
===================
1)syntax error
2)runtime error
1) try.. catch
1) try.. catch
--------------
try {
----
----
}
catch(Exception arg)
{
---
---
}
---
======================================
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
-----
}
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
extends is a keyword to get the properties from one class to another class
poly morphism
===============
poly ->many
morphism -> forms
super.propertyname()
super is keyword to access parent class property if incase if we are using same propertyname in child
class.