300+ TOP Groovy (programming language) Interview Questions [REAL TIME]

  1. 1. Explain What Is Groovy?

    Groovy is an object-oriented programming language for JVM (Java Virtual Machines). It is used to combine Java modules, to write Java application and to extend existing Java application.

  2. 2. What Are The Dependencies For Groovy?

    As well as Java 1.4 and the Groovy jar we also depend at runtime on the ASM library.


  3. Adv Java Interview Questions

  4. 3. Mention What Relational Operators Is Used For In Groovy?

    Relational operators allows you to compare between objects, to check whether the two objects are different or same or if one is less than, greater than or equal to others.

  5. 4. Things Work If I Use Suns Conventions And Put { On The Same Line, But If I Add A New Line Things Break?

    When using closures with method calls we have some syntax sugar in Groovy which is sensitive to white space (newlines to be precise). Please see this description in common gotchas for a full description.


  6. Adv Java Tutorial

  7. 5. Why Use Groovy?

    • For Java programmers it provides familiar syntax
    • It has a rich stock of Java Libraries
    • It easily integrate with your existing infrastructure like Servlet Containers, App Servers, Loads of databases with JDBC drivers,
    • Completely Object Oriented
    • It possesses a reusable and assignable pieces of code
    • Operators can be overloaded
    • Literal declaration for maps, arrays, ranges and regular expressions
    • It has efficient object navigation

  8. Selenium Interview Questions

  9. 6. What Is The Licence For Groovy?

    Groovy is open source using a BSD / Apache style licence

  10. 7. When “propertymissing (string)” Method Is Called?

    The “propertyMissing (String)” method is called when no getter method for a given property can be detected by the Groovy runtime.


  11. Selenium Tutorial
    Hibernate Interview Questions

  12. 8. How Can I Add Stuff To The Classpath When Running Things In Groovysh Or Groovy?

    You can add things to your $CLASSPATH environment variable. Another popular option is to create a .groovy/lib directory in your home directory and add whatever jars you want to be available by default. e.g. if you wish to connect to your favourite JDBC database and do some scripting with it then add your JDBC driver to ~/.groovy/lib.

  13. 9. What Is The Limitation Of Groovy?

    • Groovy can be slower
    • Groovy might need lots of memory
    • Groovy start up time requires improvement
    • It requires Java knowledge
    • It takes sometimes to get use to like New Syntax, closures, default typing,
    • Documentation is thin

  14. Java applet Interview Questions

  15. 10. I Get Errors When Trying To Run Groovy, Groovysh Or Groovyconsole. Whats Wrong?

    Groovy depends on JDK 1.4 or later. Common errors people have when trying to run Groovy is that there’s an old groovy jar on the CLASSPATH somewhere (have you checked in java/lib/ext?) or that JAVA_HOME points to an old JDK before JDK 1.


  16. Hibernate Tutorial

  17. 11. Explain What Does The Jsonslurper Class Indicates?

    The JsonSlurper is a class that parses JSON text or reader content into Groovy data structures (objects) such as lists, maps, and primitive types like double, Boolean, string and Integer.


  18. Amazon Web Services (AWS) Interview Questions

  19. 12. Explain How Scripts Are Run In Groovy?

    Groovy supports plain script; it does not require a class declaration. At the front of the script, imports are supported at the same way that it can be at the front of a class. In Groovy, you have to use word def to declare a function outside of a class.


  20. Adv Java Interview Questions

  21. 13. Explain The Role Of Grape Dependency In Groovy?

    Grape is a JAR dependency manager included into Groovy. It allows you to add quickly maven repository dependencies to your classpath, making scripting easier. The simplest use is adding an annotation to your script.


  22. Spring MVC Framework Tutorial

  23. 14. Mention What Are Some Features Does Groovy Jdk Offers?

    Groovy has added new methods compare to old version like

    • Various array types and object streams with newly Groovy oriented methods like Object.every(), Object.each() etc. and also include new features like “String BufferedReader.getText()” and “InputStream.eachLine(Closure)”.
  24. 15. Explain Groovydoc Comment?

    Like multiline comments, GroovyDoc comments are multiline but it starts with a /** and end with */. Those comments are related with

    • Type definitions (classes, interfaces, enums, annotations)
    • Fields and properties definitions
    • Methods definitions

  25. Adobe Analytics Interview Questions

  26. 16. Mention What Is The Role Of Closure And Listeners In Groovy?

    Groovy does not support anonymous inner classes; it is possible to determine action listeners inline through the means of closures. In Groovy, listeners closure are used as a ListenerAdapter where only one method of interest is overridden.


  27. Agile Methodology Tutorial

  28. 17. Explain What Is Groovysh?

    Groovysh is a command line application that enables an easy access to evaluate Groovy expressions, define classes and run experiments.


  29. Spring MVC Framework Interview Questions

  30. 18. Explain How You Can Add Stuff To The Classpath When Running Things In Groovy Or Groovysh?

    You can add things to your $CLASSPATH environment variable. Another possibility is to build a .groovy/lib directory in your home directory and append whatever jars you want to be available by default.


  31. Selenium Interview Questions

  32. 19. Explain How You Can Include A Groovy Script In Another Groovy?

    You can include a groovy script with another groovy by using the following code. When put this code at the top of the script it will bring in the contents of a groovy file.

    Evaluate(new file(“../tools/Tools.groovy”))

  33. 20. Mention What Is The License For Groovy?

    Groovy depend at runtime on the ASM library as well as Java 1.4 and the Groovy jar.


  34. Agile Scrum Master Interview Questions

  35. 21. Explain How Groovy String Is Expressed?

    Groovy string is referred as Gstring.

    • It is surrounded by double quotes, for regular strings it uses single quotes
    • It may contain Groovy Expressions noted in ${}
    • Square bracket syntax may be applied like charAt(i)
  36. 22. Explain What Is Expandometaclass In Groovy?

    ExpandoMetaClass is used to add methods, properties, static methods and constructors. Expandoclass does not inherited by default; you have to call ExpandoMetaClass.enableGlobally().

  37. 23. What Is Grails?

    Grails is an open source web application framework that uses the Groovy and Java as programming language, this framework use another frameworks like Spring, Hibernate, SiteMesh and have and embebed H2 database, Tomcat server and ORM(GORM). this framework follow some design patters as Model View Controller(MVC), Convention Over Configuration(CoC), Don’t repeat yourself(DRY) and runs over the Java Virtual Machine(JVM).


  38. Agile Ux Designer Interview Questions

  39. 24. What Is Orm?

    means object relational mapping, A simple answer is that you wrap your tables or stored procedures in classes in your programming language, so that instead of writing SQL statements to interact with your database, you use methods and properties of objects.

    It’s a library or framework that help you to map/convert your models in to tables in your database, It’s like a mediator or an intermediate that avoid that you have to write SQL code and allows you to interact with the DB using a programming language like groovy without have to worry about write SQL code or what kind of database are you using, you can switch from mySql to Oracle DB modifying only 4 lines of code, an example of what is an ORM It’s the Hibernate Framework.


  40. Hibernate Interview Questions

  41. 25. What Is Gorm?

    GORM is Grails’ object relational mapping (ORM) implementation. Under the hood it uses Hibernate (a very popular and flexible open source ORM solution) and thanks to the dynamic nature of Groovy with its static and dynamic typing, along with the convention of Grails, there is far less configuration involved in creating Grails domain classes.

  42. 26. What Is The Command To Create A New Application In Grails?

    grails create-app “the name of your app”


  43. Agile Methodology Interview Questions

  44. 27. What Is The Command To Run A Grails Application?

    grails run-app


  45. Java applet Interview Questions

  46. 28. What Is The Command To Create A Domain Class?

    grails create-domain-class “packpage” +”name of your domain class”

  47. 29. What Is The Command To Create A Controller?

    grails create-controller  “packpage” +”name of your domain class”

  48. 30. What Are The Default Environments In Grails?

    Development, Test And Production

  49. 31. What Is The Command To Generate A War File?

    grails war

  50. 32. What Is The Command To Run Your Application In A Different Environment That Development?

    grails  -Dgrails.env=test run-app

  51. 33. What Is The Command To Run You Application In A Different Port That 8080?

    grails  -Dserver.port=9090 run-app


  52. Amazon Web Services (AWS) Interview Questions

  53. 34. What Is The Command To Do Static Scaffolding Of A Controller?

    grails generate-controller “packpage”+”domain class”

  54. 35. What Is The Command To Do Static Scaffolding Of The View Of A Domain?

    grails generate-views “packpage”+”domain class”

  55. 36. What Is The Command To Generate The Static Scaffolding Of The Controllers And Views Of A Domain Class?

    grails generate-all “packpage”+”domain class”


  56. Adobe Analytics Interview Questions

  57. 37. What Is The Command To Generate The Static Scaffolding Of The Controllers And Views Of All Your Domain Classes?

    grails generate-all “*”

  58. 38. What Is The Command To Stop Your Application?

    grails stop-app

  59. 39. What Is The Command To Test Your Application?

    grails test-app

  60. 40. What Is The Command To Test Your Application For Unit Test Only?

    grails test-app –unit


  61. Spring MVC Framework Interview Questions

  62. 41. What Is The Command To Test Your Application For Integration Test Only?

    grails test-app –integration

  63. 42. What Is The Command To Rerun Test In Your Application?

    grails test-app –rerun


  64. Agile Scrum Master Interview Questions

  65. 43. What Is The Command To See Your Grails Version?

    grails  -version

  66. 44. What Is The Command To Create The Unit Test Of A Domain Class?

    grails create-unit-test “packpage”+”domain class”

  67. 45. What Is The Command To Create The Integration Test Of A Domain Class?

    grails create-integration-test “packpage”+”domain class”

  68. 46. What Is Data Binding?

    It’s the act of binding incoming request parameters on to the properties of an object.

  69. 47. Where Do You Setup Your Db , Hibernate Version And Environments?

    DataSource.groovy

  70. 48. Where Do You Setup Your Dependency Manager, Your Repositories, Dependencies And Pluguins?

    BuildConfing.groovy

  71. 49. What Is The Difference Between Buildconfig.groovy And Config.groovy?

    that Config include configuration needed to run your application and BuildConfig include configuration to build and deploy your application.

  72. 50. What Do You Have To Do If You Don’t Want That A Property Of Your Domain Be Mapped To The Db?

    In your domain class:

    static transient[‘cant save this’]

  73. 51. What Is Methaprogramming?

    It’s the groovy ability to add new methods or variables to classes dynamically at run time, and without torching the code.

  74. 52. Could You Give Me An Example Of Methaprogramming In Grails?

    The dynamic finders in the domains class.

  75. 53. What Type Of Looking Is By Default In Grails Optimistic Or Pessimist Looking?

    optimistic looking:
    Optimistic locking is a feature of Hibernate which involves storing a version value in a special version column in the database that is incremented after each update.

  76. 54. What Is Pessimistic Locking.

    Locking a row until the current transaction is completed. This has the implication that other read operations will be blocking until the lock is released.

  77. 55. How Do You Use Pessimist Looking In A Domain Class?

    Call  “.lock()” method on domain instance.

    Example.

    def airport = Airport.get(10)
    airport.lock() // lock for update
    airport.name = “Heathrow”
    airport.save()
     
    or defining in your domain class “version= false”
    Example:
    class Person {
        …
        static mapping = {
            version false // here you disability optimist looking
            autoTimestamp false
        }
    }

  78. 56. What Method Do You Use To Check If Any Field Of An Object Has Been Modified?

    isDirty

    getDirtyPropertyNames : to get names of modified fields.

  79. 57. What Is Dynamic Finders?

    Are the methods auto generated by grails based on fields of the domain class.

    Example. class Book {

    String title
    Date releaseDate
    Author author
       }
                   
    def book = Book.findByTitle(“The Stand”)
    book = Book.findByTitleLike(“Harry Pot%”)

  80. 58. Associations In Gorm Are By Default Lazy Or Eager?

    lazy

  81. 59. How Do You Configuring Eager Fetching In A Domain Class?

    using:

    lazy: false
    or
    fetch: ‘join’

    Example:

    class Airport {
        String name
        static hasMany = [flights: Flight]
        static mapping = {
            flights lazy: false //here you configure eager fetching
        }
    }

    class Person {
        String firstName
        Pet pet
        static hasMany = [addresses: Address]
        static mapping = {
            addresses lazy: false
            pet fetch: ‘join’ //this is another way to configure eager fetching
        }
    }

  82. 60. What Is The Configuration File To Define Url Pattern And Its Controller And Action Name?

    grails-app/conf/UrlMappings.groovy.

  83. 61. How Do You Secure Your Grails Application?

    Use Grails Filter

  84. 62. How Can I Turn On Logging For Hibernate In Order To See Sql Statements, Input Parameters And Output Results?

    Edit your Config.groovy file. Find the line with:

    hibernate = “off”
    and replace it with:
    hibernate.SQL=”trace,stdout”
    hibernate.type=”trace,stdout”

  85. 63. How Do You Render A Domain Object As Xml Or Json?

    render Book.list(object) as JSON
    render Book.get(object) as XML

  86. 64. How Do You Access Servlet Attributes From Controller?

    servletContext
    servletContext is available in controller.

  87. 65. What Is Javascript Tag In Gsp?

    Includes JavaScript libraries and scripts as well as providing a shorthand for inline JavaScript.

  88. 66. What Is The Name Of Config File To Define Database Connection Properties?

    grails-app/conf/DataSource.groovy.

  89. 67. What Is Command To Refresh Dependencies?

    grails refresh-dependencies

  90. 68. What Option Do You Use To Create War File For Specific Environment?

    -Dgrails.env

    Example : grails -Dgrails.env=dev war

  91. 69. By Default Services In Grail Is Singleton Or Prototype?

    Singleton.

  92. 70. What Is The Command To Create A Service In Grails?

    grails create-service “packpage”+”service name”

  93. 71. What Is The Command To Create A Tag Library In Grails?

    grails create-tag-library+ “packpage”+”name”

  94. 72. What Is Are The Closures In Groovy?

    A closure in Groovy is an open, anonymous, block of code that can take arguments, return a value and be assigned to a variable.

  95. 73. How Do You Inject A Service In Your Controller?

    def taskService

  96. 74. How Render A Template In A View In Grails?

    use the tag:

  97. 75. How You Can Load Preload Data When Startup Your Aplication?

    using Boostrap.groovy

  98. 76. How Use Dynamic Scaffolding In Your App?

    in your controller:

    def scaffold=true  or def scaffold=”the name of your domain class”

  99. 77. What Is A Template In Grails?

    It’s a reusable part of a view that can be used to render a small part of a view.

  100. 78. What Is A Grails Pluguin?

    It’s a bundle/set of functionality to a desired propose that can be installed in your grails application.

  101. 79. How You Can Use A Tag Library In Your View?

  102. 80. What Is The Command To Compile Your Grails Application?

    grails compile

  103. 81. What Is The Difference Between User.findbyname() And User.findallbyname() In The Dynamic Finders?

    That Findbyname Return The First Result And Findallbyname Return A List With All The Results

  104. 82. How You Can Map Directly A Domain Class To An Specific Table In Your Db?

    in your domain class:

    class Person {
        …
        static mapping = {
            table ‘people’///this is the mapping of the domain in the table
        }
    }

  105. 83. How You Can Map Directly A Property Of A Domain Class To An Specific Column In Table Of Your Db?

    class Person {
        String firstName
        static mapping = {
            table ‘people’
            firstName column: ‘First_Name’ ///this is the mapping of the columm in the table
        }
    }

  106. 84. What Is Sitemesh?

    It’s a HTML templating framework

  107. 85. How You Can Validate Your Domain Classes Against Invalid Data?

    using :  static constraints{ }

  108. 86. How You Can Have Control Over The Way Grails Mapping The Urls In Your Application?

    In “conf/UrlMappings.groovy” you can customize how grails maps the URLs in your application   

  109. 87. What Is The Command To Run Your App In A Custom Environment?

    grails -Dgrails.env=”your custom enviroment” run-app

  110. 88. How You Can Use A Namespace Different Than “g: ” To Render Your Tag Library In Your Views?

    using the  line in your tag library:

    static namespace = “your custom namespace”

  111. 89. What Are The Differents Options To “dbcreate” Inside A Data Source Of An Environment?

    ‘create’, ‘create-drop’, ‘update’, ‘validate’ and ‘ null ‘

  112. 90. What Happens With The Db If You Have ‘create’ In The Option “dbcreate” Of Your Data Source?

    Drops the existing schemaCreates the schema on startup, dropping existing tables, indexes, etc. first.

  113. 91. What Happens With The Db If You Have ‘create-drop’ In The Option “dbcreate” Of Your Data Source?

    Same as create, but also drops the tables when the application shuts down cleanly.

  114. 92. What Happens With The Db If You Have ‘update’ In The Option “dbcreate” Of Your Data Source?

    Creates missing tables and indexes, and updates the current schema without dropping any tables or data. Note that this can’t properly handle many schema changes like column renames (you’re left with the old column containing the existing data).

  115. 93. What Happens With The Db If You Have ‘validate’ In The Option “dbcreate” Of Your Data Source?

    Makes no changes to your database. Compares the configuration with the existing database schema and reports warnings.

  116. 94. What Happens With The Db If You Have ‘nothing/null’ In The Option “dbcreate” Of Your Data Source?

    Does nothing with your data base

  117. 95. What Is New Scope Available In The Grails Services Which Makes Sure That A New Service Will Be Created For The Current And Next Request Only?

    Flash

  118. 96. What Annotation Is Used For Unit Testing Of Grails Controller?

    grails.test.mixin.TestFor

  119. 97. How You Can Create A One-to-many Relationship In Gorm?

    you can use static hasMany property at the “one” side: 

    class User {
        static hasMany = [articles: Article]
    }
     
    class Article {
    }

  120. 98. How You Can Create A Bidirectional Relationships In Gorm?

    using:

    static belongsTo = User

    example:

    class User {
        static hasMany = [articles: Article]
    }
    class Article {
        static belongsTo = User
    }

  121. 99. How You Can Create One-to-one Relationship In Gorm?

    There are two ways of specifying a one-to-one relationship:

    First Add an article property and the unique constraint to the User domain:

    class User {
        Article article
        static constraints = {
            article unique: true
        }
    }
    class Article {
        static belongsTo = [user: User]
    }

                            Second use the hasOne property on the owning (User) side:
    class User {
        static hasOne = [article: Article]
    }
    class Article {
        static belongsTo = [user: User]
                            }

  122. 100. How You Can Create Many-to-many Relationship In Gorm?

    Many-to-many relationships in Grails can be specified by defining a hasMany property on both sides and having a belongsTo on the owned side:

    class Tag {
        static belongsTo = Post
        static hasMany = [posts: Post]
    }
    class Post {
        static hasMany = [tags: Tag]
    }

  123. 101. What Is The Use Of Flush Option In Save Operation Of A Domain?

    Saves the row immediately without any delay.

    Example 

    def book = new Book(title:”New Grails Book”)
    book.save(flush:true)

  124. 102. How Can You Install A Pluguin In Your Grails Application?

    you have to write your pluguin inside the pluguins Block/closure {} in the BuildConfig.groovy file and you have to specify if your pluguin works at run time or compilation time.

    Example:

    plugins {
                            build “:tomcat:7.0.55”
                            compile “:scaffolding:2.1.2”
                            runtime “:jquery:1.11.1”
    }

  125. 103. How Can You Made A All The Method Of A Service In Grails Be Transactional?

    with the anotation @Transactional above the class’s name

    Example:

    import grails.transaction.*
    @Transactional
    class CountryService {
    }

  126. 104. How You Can Made A Method Of A Service Be Transactional?

    With the anotation @Transactional above the method’s name of the service

    Example:

    import grails.transaction.Transactional

    class BookService {
    @Transactional
        def updateBook() {
            // …
        }
    }

  127. 105. How You Can Make A Method Not Transactional If The Whole Class Was Marked As Transactional?

    using the annotation @NotTransactional above the method’s name in the service

    Example:

    import grails.transaction.Transactional

    @Transactional
    class BookService {
        @NotTransactional
        def listBooks() {
                     Book.list()
            }
        }