Saturday 12 January 2019

Groovy Tutorial

Install and setup Groovy
HelloWorld Application
Comments
Shebang line
Tools to execute groovy
Evaluate expressions using groovy command
Generate .class file from groovy code
Strings
Assertions
Beans in Groovy
Range operator
No primitive types in Groovy
Optional typing
Operators
    Arithmetic Operators
        intdiv: Perform integer division
        Unary Arithmetic Operators
    Relational Operators
    Logical Operators
        Precedence of Logical Operators
    Bitwise operators
    
    Not operator
    Ternary operator (?:)
Elvis operator (?:)
    Object Operators
        Safe Navigation Operator
        Direct field access operator (@)
        Method pointer operator (.&)
    Regular Expression Operators
        Pattern Operator (~)
        Find Operator (=~)
        Match Operator
    Other operators
        Spread Operator (*.)
        Spread Operator Vs Iterable interface
        Spread operator and nested objects
        Spread method arguments using spread operator
        Spread the list elements
        Spread map elements
    Range (..) operator
        Specify ranges to custom types
    Spaceship (<=>) operator
    Subscript Operator
    Membership Operator
    Identity Operator (==)
    Coercion operator (as)
    Diamond Operator (<>)
    call operator
Operator Overloading
Working with Collections
    Lists
        Construct list from another list
        How to get the element at given position?
        lists: Set the element at given position
        List can take object of any type
        Lists can take negative indexes
        List in boolean context
        Iterate over the list
        collect() : Transform the elements of list to new list
        List: find(): Find first element that matches given criteria
        List: findAll: Find all the elements that matches to given criteria
        List: findIndexOf: Find index of first element that matches to given criteria
        List: indexOf: Return the index of an element in the list
        List: lastIndexOf: Return the index of an element from the end of list
        List: every(): Return true if all the elements in the list matches to given criteria
        List: any: Check whether any one element matches to given criteria
        List: sum(): Return sum of all the elements in the list
        List: join: Join the string using given separator
        List: inject: Perform reduce operation
        List: max: Find maximum element in the list
        List: append elements to list
        Spread the list elements
        List: flatten: Flatten list elements
        List: remove element from the list
        Remove all the elements from list
        Check for existence of an element in the list
        list: Count number of occurrences of given value
        Count number of values that matches to given predicate
        Get intersection of two lists
        List: Check whether lists are disjoint or not
        Sort elements of a list
        Duplicate elements of a list
    Working with Maps
        Insert elements into a map
        Get elements of a map
        Create empty map
        Get size of map
        Keys in the map are string by default
        Maps in Groovy are heterogeneous
        Clone map
        Map: Access the keys using . notation
        Iterating over maps
        Adding elements to the map
        Remove all the elements from the map
        Map: find: Find the first element that matches to given closure
        Map: findAll: Find all the elements that matches to given criteria
        Map: collect(): Collect the information
        map: every: Check whether all the elements satisfy given criteria or not
        any: check whether any entry matches to the predicate
        Map: Group the elements
Working with Closures
    closure.getParameterTypes().size(): Check number of arguments this closure takes
    Closure: Currying
Rules while evaluating the expressions
Assignment vs if statement
Pass custom objects to switch statement
Overloading of isCase method
Classes
    Accessing fields of a class
    Constructor invocation
    Methods
        Method named parameters
        Default arguments to a method
        Method vs checked exceptions
Fields
Properties
List all the properties of a class
Read a file line by line
Get the package name of a class
parse xml file
Print all the file names in a directory recursively
print first 10 fibonacci numbers
Print elements of list without using a counter and list size
Convert string to int

Previous                                                 Next                                                 Home

No comments:

Post a Comment