Groovy On Grails Interview Questions & Answers

  1. Question 1. What’s Is Groovy?

    Answer :

    is an dynamic, object oriented, scripting language that it’s compiled in byte code and runs over the JVM. this language include some features like metha programing, closures, etc.

  2. Question 2. What Is Grails?

    Answer :

    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 an embedded H2 database, Tomcat server and ORM(GORM). this framework follow some design patterns as Model View Controller(MVC), Convention Over Configuration(CoC), Don’t repeat yourself(DRY) and runs over the Java Virtual Machine(JVM).

  3. Web Services Interview Questions

  4. Question 3. What Is Orm?

    Answer :

    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.

  5. Question 4. What Is Gorm?

    Answer :

    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.

  6. Web Services Tutorial

  7. Question 5. What Is The Command To Create A New Application In Grails?

    Answer :

    grails create-app “the name of your app”

  8. HTML 5 Interview Questions

  9. Question 6. What Is The Command To Run A Grails Application?

    Answer :

    grails run-app

  10. Question 7. What Is The Command To Create A Domain Class?

    Answer :

    Grails create-domain-class “package” +”name of your domain class”.

  11. HTML 5 Tutorial
    J2EE Interview Questions

  12. Question 8. What Is The Command To Create A Controller?

    Answer :

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

  13. Question 9. What Are The Default Environments In Grails?

    Answer :

    Development, Test And Production

  14. Angular JS Interview Questions

  15. Question 10. What Is The Command To Generate A War File?

    Answer :

    grails war

  16. J2EE Tutorial

  17. Question 11. What Is The Command To Run Your Application In A Different Environment That Development?

    Answer :

    grails  -Dgrails.env=test run-app

  18. CSS Advanced Interview Questions

  19. Question 12. What Is The Command To Run You Application In A Different Port Than 8080?

    Answer :

    grails  -Dserver.port=9090 run-app

  20. Web Services Interview Questions

  21. Question 13. What Is The Command To Do Static Scaffolding Of A Controller?

    Answer :

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

  22. CSS Advanced Tutorial

  23. Question 14. What Is The Command To Do Static Scaffolding Of The View Of A Domain?

    Answer :

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

  24. Question 15. What Is The Command To Generate The Static Scaffolding Of The Controllers And Views Of A Domain Class?

    Answer :

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

  25. Javascript Advanced Interview Questions

  26. Question 16. What Is The Command To Generate The Static Scaffolding Of The Controllers And Views Of All Your Domain Classes?

    Answer :

    grails generate-all “*”

  27. Javascript Advanced Tutorial

  28. Question 17. What Is The Command To Stop Your Application?

    Answer :

    grails stop-app

  29. Restful web service Interview Questions

  30. Question 18. What Is The Command To Test Your Application For Unit Test Only?

    Answer :

    grails test-app –unit

  31. HTML 5 Interview Questions

  32. Question 19. What Is The Command To Test Your Application For Integration Test Only?

    Answer :

    grails test-app –integration

  33. Restful web service Tutorial

  34. Question 20. What Is The Command To Rerun Test In Your Application?

    Answer :

    grails test-app –rerun

  35. Groovy (programming language) Interview Questions

  36. Question 21. What Is The Command To See Your Grails Version?

    Answer :

    grails  -version

  37. Question 22. What Is The Command To Create The Unit Test Of A Domain Class?

    Answer :

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

  38. Question 23. What Is The Command To Create The Integration Test Of A Domain Class?

    Answer :

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

  39. Advanced jQuery Interview Questions

  40. Question 24. What Is Data Binding?

    Answer :

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

  41. J2EE Interview Questions

  42. Question 25. Where Do You Setup Your Db , Hibernate Version And Environments?

    Answer :

    DataSource.groovy

  43. Question 26. Where Do You Setup Your Dependency Manager, Your Repositories, Dependencies And Plugins?

    Answer :

    BuildConfig.groovy

  44. Restaurant Manager Interview Questions

  45. Question 27. What Is The Difference Between Buildconfig.groovy And Config.groovy?

    Answer :

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

  46. Angular JS Interview Questions

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

    Answer :

    in your domain class:

    static transient[‘can’t save this’]

  48. Question 29. What Is Metaprogramming?

    Answer :

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

  49. Soap Web Services Interview Questions

  50. Question 30. Could You Give Me An Example Of Meta Programming In Grails?

    Answer :

    The dynamic finders in the domains class.

  51. Question 31. What Is Pessimistic Locking?

    Answer :

    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.

  52. Question 32. How Do You Configuring Eager Fetching In A Domain Class?

    Answer :

    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

        }

    }

  53. Java 9 Interview Questions

  54. Question 33. What Is The Configuration File To Define Url Pattern And Its Controller And Action Name?

    Answer :

    grails-app/conf/UrlMappings.groovy.

  55. CSS Advanced Interview Questions

  56. Question 34. What Is Another Way To Make A Transaction Method That Not Use The Transactional Annotation In Grails?

    Answer :

    Using the “.withTransaction” method

    Example:

    Account.with Transaction { status ->

        def source = Account.get(params.from)

        def dest = Account.get(params.to)

        int amount = params.amount.to Integer()

        if (source.active) {

            source.balance -= amount

            if (dest.active) {

                dest.amount += amount

            }

            else {

                status.setRollbackOnly()

            }

        }

    }

  57. Question 35. How You Can Make A Method Not Transactional If The Whole Class Was Marked As Transactional?

    Answer :

    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()

            }

        }

  58. Question 36. How You Can Made A Method Of A Service Be Transactional?

    Answer :

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

    Example:

    import grails.transaction.Transactional

    class BookService

    @Transactional

        def updateBook()

    {

            // …

        }

    }

  59. Javascript Advanced Interview Questions

  60. Question 37. How Can You Made A All The Method Of A Service In Grails Be Transactional?

    Answer :

    With the annotation @Transactional above the class’s name

    Example:

    import grails.transaction.*

    @Transactional

    class Country Service {

    }

  61. Question 38. What Is The Use Of Flush Option In Save Operation Of A Domain?

    Answer :

    Saves the row immediately without any delay.

    Example 

    def book = new Book(title:”New Grails Book”)

    book.save(flush:true)

  62. Question 39. How You Can Create Many-to-many Relationship In Gorm?

    Answer :

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

    class Tag {

        static belongsTo = Post

        static hasMany = [posts: Post]

    }

    class Post {

        static hasMany = [tags: Tag]

    }

  63. Question 40. What Is A Grails Plugin?

    Answer :

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

  64. Restful web service Interview Questions

  65. Question 41. How Use Dynamic Scaffolding In Your App?

    Answer :

    in your controller:

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

  66. Question 42. How Render A Template In A View In Grails?

    Answer :

    use the tag:

  67. Groovy (programming language) Interview Questions

  68. Question 43. How Do You Inject A Service In Your Controller?

    Answer :

    def taskService

  69. Question 44. What Option Do You Use To Create War File For Specific Environment?

    Answer :

    Dgrails.env

    Example : grails -Dgrails.env=dev war