YouTube Icon

Interview Questions.

Top 100+ Groovy (programming Language) Interview Questions And Answers - May 30, 2020

fluid

Top 100+ Groovy (programming Language) Interview Questions And Answers

Question 1. Explain What Is Groovy?

Answer :

Groovy is an item-orientated programming language for JVM (Java Virtual Machines). It is used to combine Java modules, to jot down Java application and to extend existing Java utility.

Question 2. What Are The Dependencies For Groovy?

Answer :

As well as Java 1.Four and the Groovy jar we also rely at runtime on the ASM library.

Adv Java Interview Questions
Question 3. Mention What Relational Operators Is Used For In Groovy?

Answer :

Relational operators permits you to examine between items, to test whether or not the 2 items are extraordinary or equal or if one is much less than, extra than or identical to others.

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

Answer :

When using closures with technique calls we've got a few syntax sugar in Groovy that is sensitive to white space (newlines to be particular). Please see this description in commonplace gotchas for a complete description.

Adv Java Tutorial
Question five. Why Use Groovy?

Answer :

For Java programmers it gives acquainted syntax
It has a rich inventory of Java Libraries
It effortlessly combine with your present 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 may be overloaded
Literal statement for maps, arrays, stages and everyday expressions
It has green item navigation
Selenium Interview Questions
Question 6. What Is The Licence For Groovy?

Answer :

Groovy is open source the use of a BSD / Apache style licence

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

Answer :

The “propertyMissing (String)” approach is known as while no getter approach for a given belongings can be detected via the Groovy runtime.

Selenium Tutorial Hibernate Interview Questions
Question 8. How Can I Add Stuff To The Classpath When Running Things In Groovysh Or Groovy?

Answer :

You can add things in your $CLASSPATH surroundings variable. Another popular choice is to create a .Groovy/lib directory in your home directory and upload anything jars you need to be available by way of default. E.G. If you want to hook up with your preferred JDBC database and do a little scripting with it then upload your JDBC driver to ~/.Groovy/lib.

Question 9. What Is The Limitation Of Groovy?

Answer :

Groovy can be slower
Groovy might want plenty of reminiscence
Groovy begin up time calls for improvement
It requires Java understanding
It takes sometimes to get use to like New Syntax, closures, default typing,
Documentation is skinny
Java applet Interview Questions
Question 10. I Get Errors When Trying To Run Groovy, Groovysh Or Groovyconsole. Whats Wrong?

Answer :

Groovy depends on JDK 1.4 or later. Common errors human beings have whilst trying to run Groovy is that there’s an vintage groovy jar at the CLASSPATH somewhere (have you checked in java/lib/ext?) or that JAVA_HOME factors to an antique JDK earlier than JDK 1.

Hibernate Tutorial
Question eleven. Explain What Does The Jsonslurper Class Indicates?

Answer :

The JsonSlurper is a category that parses JSON text or reader content into Groovy records systems (gadgets) consisting of lists, maps, and primitive sorts like double, Boolean, string and Integer.

Amazon Web Services (AWS) Interview Questions
Question 12. Explain How Scripts Are Run In Groovy?

Answer :

Groovy helps simple script; it does now not require a category assertion. At the the front of the script, imports are supported on the identical way that it can be on the front of a class. In Groovy, you need to use phrase def to declare a feature outside of a category.

Adv Java Interview Questions
Question thirteen. Explain The Role Of Grape Dependency In Groovy?

Answer :

Grape is a JAR dependency manager blanketed into Groovy. It permits you to feature quickly maven repository dependencies in your classpath, making scripting less complicated. The only use is including an annotation for your script.

Spring MVC Framework Tutorial
Question 14. Mention What Are Some Features Does Groovy Jdk Offers?

Answer :

Groovy has brought new strategies evaluate to old version like

Various array sorts and item streams with newly Groovy oriented strategies like Object.Every(), Object.Each() and many others. And also include new functions like “String BufferedReader.GetText()” and “InputStream.EachLine(Closure)”.
Question 15. Explain Groovydoc Comment?

Answer :

Like multiline remarks, GroovyDoc feedback are multiline however it starts offevolved with a /** and cease with */. Those comments are related with

Type definitions (instructions, interfaces, enums, annotations)
Fields and homes definitions
Methods definitions
Adobe Analytics Interview Questions
Question sixteen. Mention What Is The Role Of Closure And Listeners In Groovy?

Answer :

Groovy does not help anonymous inner training; it's far viable to determine movement listeners inline through the way of closures. In Groovy, listeners closure are used as a ListenerAdapter where best one method of hobby is overridden.

Agile Methodology Tutorial
Question 17. Explain What Is Groovysh?

Answer :

Groovysh is a command line application that permits an smooth get entry to to assess Groovy expressions, define classes and run experiments.

Spring MVC Framework Interview Questions
Question 18. Explain How You Can Add Stuff To The Classpath When Running Things In Groovy Or Groovysh?

Answer :

You can add matters for your $CLASSPATH environment variable. Another possibility is to construct a .Groovy/lib listing in your home listing and append something jars you need to be to be had through default.

Selenium Interview Questions
Question 19. Explain How You Can Include A Groovy Script In Another Groovy?

Answer :

You can include a fab script with any other groovy by using using the following code. When positioned this code on the pinnacle of the script it's going to carry in the contents of a fab record.

Evaluate(new document(“../equipment/Tools.Groovy”))

Question 20. Mention What Is The License For Groovy?

Answer :

Groovy depend at runtime on the ASM library in addition to Java 1.4 and the Groovy jar.

Agile Scrum Master Interview Questions
Question 21. Explain How Groovy String Is Expressed?

Answer :

Groovy string is referred as Gstring.

It is surrounded by means of double charges, for ordinary strings it uses unmarried quotes
It may additionally incorporate Groovy Expressions noted in $
Square bracket syntax may be carried out like charAt(i)
Question 22. Explain What Is Expandometaclass In Groovy?

Answer :

ExpandoMetaClass is used to feature techniques, homes, static methods and constructors. Expandoclass does not inherited via default; you have to call ExpandoMetaClass.EnableGlobally().

Question 23. What Is Grails?

Answer :

Grails is an open supply net utility framework that uses the Groovy and Java as programming language, this framework use any other frameworks like Spring, Hibernate, SiteMesh and feature and embebed H2 database, Tomcat server and ORM(GORM). This framework follow a few design patters as Model View Controller(MVC), Convention Over Configuration(CoC), Don't repeat yourself(DRY) and runs over the Java Virtual Machine(JVM).

Agile Ux Designer Interview Questions
Question 24. What Is Orm?

Answer :

method object relational mapping, A simple answer is which you wrap your tables or stored processes in classes on your programming language, so that as opposed to writing SQL statements to interact with your database, you operate methods and residences of items.

It's a library or framework that assist you to map/convert your models in to tables to your database, It's like a mediator or an intermediate that avoid that you have to write SQL code and lets in you to engage with the DB using a programming language like groovy without have to fear about write SQL code or what kind of database are you using, you could transfer from mySql to Oracle DB editing best 4 traces of code, an instance of what's an ORM It's the Hibernate Framework.

Hibernate Interview Questions
Question 25. What Is Gorm?

Answer :

GORM is Grails' object relational mapping (ORM) implementation. Under the hood it makes use of Hibernate (a totally popular and bendy open source ORM answer) and way to the dynamic nature of Groovy with its static and dynamic typing, in conjunction with the convention of Grails, there's a long way less configuration involved in developing Grails domain training.

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

Answer :

grails create-app "the call of your app"

Agile Methodology Interview Questions
Question 27. What Is The Command To Run A Grails Application?

Answer :

grails run-app

Java applet Interview Questions
Question 28. What Is The Command To Create A Domain Class?

Answer :

grails create-area-elegance "packpage" +"call of your domain class"

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

Answer :

grails create-controller  "packpage" +"call of your domain magnificence"

Question 30. What Are The Default Environments In Grails?

Answer :

Development, Test And Production

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

Answer :

grails conflict

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

Answer :

grails  -Dgrails.Env=test run-app

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

Answer :

grails  -Dserver.Port=9090 run-app

Amazon Web Services (AWS) Interview Questions
Question 34. What Is The Command To Do Static Scaffolding Of A Controller?

Answer :

grails generate-controller "packpage"+"domain class"

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

Answer :

grails generate-perspectives "packpage"+"domain class"

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

Answer :

grails generate-all "packpage"+"domain elegance"

Adobe Analytics Interview Questions
Question 37. What Is The Command To Generate The Static Scaffolding Of The Controllers And Views Of All Your Domain Classes?

Answer :

grails generate-all "*"

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

Answer :

grails stop-app

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

Answer :

grails test-app

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

Answer :

grails check-app --unit

Spring MVC Framework Interview Questions
Question 41. What Is The Command To Test Your Application For Integration Test Only?

Answer :

grails check-app --integration

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

Answer :

grails take a look at-app --rerun

Agile Scrum Master Interview Questions
Question forty three. What Is The Command To See Your Grails Version?

Answer :

grails  -model

Question forty four. What Is The Command To Create The Unit Test Of A Domain Class?

Answer :

grails create-unit-check "packpage"+"area elegance"

Question forty five. What Is The Command To Create The Integration Test Of A Domain Class?

Answer :

grails create-integration-take a look at "packpage"+"area magnificence"

Question 46. What Is Data Binding?

Answer :

It's the act of binding incoming request parameters on to the houses of an object.

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

Answer :

DataSource.Groovy

Question forty eight. Where Do You Setup Your Dependency Manager, Your Repositories, Dependencies And Pluguins?

Answer :

BuildConfing.Groovy

Question forty nine. What Is The Difference Between Buildconfig.Groovy And Config.Groovy?

Answer :

that Config consist of configuration had to run your software and BuildConfig encompass configuration to build and installation your utility.

Question 50. 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 area magnificence:

static brief['cant save this']

Question 51. What Is Methaprogramming?

Answer :

It's the groovy potential to feature new strategies or variables to training dynamically at run time, and without torching the code.

Question fifty two. Could You Give Me An Example Of Methaprogramming In Grails?

Answer :

The dynamic finders inside the domains magnificence.

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

Answer :

positive looking: Optimistic locking is a function of Hibernate which includes storing a version cost in a special model column in the database that is incremented after every update.

Question 54. What Is Pessimistic Locking.

Answer :

Locking a row till the cutting-edge transaction is finished. This has the implication that other read operations could be blocking off until the lock is released.

Question fifty five. How Do You Use Pessimist Looking In A Domain Class?

Answer :

Call  ".Lock()" approach on domain instance.

Example.

Def airport = Airport.Get(10)
airport.Lock() // lock for replace
airport.Call = "Heathrow"
airport.Keep()
 
or defining to your area class "version= false"
Example:
class Person 
    …
    static mapping = 
        version false // here you disability optimist searching
        autoTimestamp false
    


Question fifty six. What Method Do You Use To Check If Any Field Of An Object Has Been Modified?

Answer :

isDirty

getDirtyPropertyNames : to get names of modified fields.

Question fifty seven. What Is Dynamic Finders?

Answer :

Are the techniques vehicle generated through grails primarily based on fields of the area magnificence.

Example. Elegance Book 

String title
Date releaseDate
Author creator
   
               
def book = Book.FindByTitle("The Stand")
e-book = Book.FindByTitleLike("Harry Pot%")

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

Answer :

lazy

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

Answer :

using:

lazy: fake
or
fetch: 'be part of'

Example:

magnificence Airport 
    String call
    static hasMany = [flights: Flight]
    static mapping = 
        flights lazy: fake //here you configure eager fetching
    


magnificence Person 
    String firstName
    Pet pet
    static hasMany = [addresses: Address]
    static mapping = 
        addresses lazy: fake
        pet fetch: 'be part of' //that is another way to configure eager fetching
    


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

Answer :

grails-app/conf/UrlMappings.Groovy.

Question sixty one. How Do You Secure Your Grails Application?

Answer :

Use Grails Filter

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

Answer :

Edit your Config.Groovy record. Find the line with:

hibernate = "off"
and replace it with:
hibernate.SQL="trace,stdout"
hibernate.Kind="hint,stdout"

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

Answer :

render Book.Listing(item) as JSON
render Book.Get(object) as XML

Question sixty four. How Do You Access Servlet Attributes From Controller?

Answer :

servletContext
servletContext is available in controller.

Question sixty five. What Is Javascript Tag In Gsp?

Answer :

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

Question sixty six. What Is The Name Of Config File To Define Database Connection Properties?

Answer :

grails-app/conf/DataSource.Groovy.

Question 67. What Is Command To Refresh Dependencies?

Answer :

grails refresh-dependencies

Question sixty eight. What Option Do You Use To Create War File For Specific Environment?

Answer :

-Dgrails.Env

Example : grails -Dgrails.Env=dev warfare

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

Answer :

Singleton.

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

Answer :

grails create-carrier "packpage"+"service name"

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

Answer :

grails create-tag-library+ "packpage"+"name"

Question seventy two. What Is Are The Closures In Groovy?

Answer :

A closure in Groovy is an open, anonymous, block of code that could take arguments, go back a fee and be assigned to a variable.

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

Answer :

def taskService

Question seventy four. How Render A Template In A View In Grails?

Answer :

use the tag:
<g:render  template="form"/>

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

Answer :

using Boostrap.Groovy

Question 76. How Use Dynamic Scaffolding In Your App?

Answer :

on your controller:

def scaffold=proper  or def scaffold="the call of your area class"

Question 77. What Is A Template In Grails?

Answer :

It's a reusable a part of a view that may be used to render a small part of a view.

Question seventy eight. What Is A Grails Pluguin?

Answer :

It's a package/set of functionality to a preferred recommend that may be mounted in your grails software.

Question seventy nine. How You Can Use A Tag Library In Your View?

Answer :

<g:"your tag library name" />

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

Answer :

grails bring together

Question eighty one. What Is The Difference Between User.Findbyname() And User.Findallbyname() In The Dynamic Finders?

Answer :

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

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

Answer :

for your domain class:

class Person 
    …
    static mapping = 
        desk 'human beings'///that is the mapping of the domain inside the desk
    


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

Answer :

class Person 
    String firstName
    static mapping = 
        desk 'human beings'
        firstName column: 'First_Name' ///this is the mapping of the columm within the table
    


Question 84. What Is Sitemesh?

Answer :

It's a HTML templating framework

Question eighty five. How You Can Validate Your Domain Classes Against Invalid Data?

Answer :

the usage of :  static constraints 

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

Answer :

In "conf/UrlMappings.Groovy" you could personalize how grails maps the URLs in your utility   

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

Answer :

grails -Dgrails.Env="your custom enviroment" run-app

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

Answer :

the usage of the  line for your tag library:

static namespace = "your custom namespace"

Question 89. What Are The Differents Options To "dbcreate" Inside A Data Source Of An Environment?

Answer :

'create', 'create-drop', 'replace', 'validate' and ' null '

Question ninety. What Happens With The Db If You Have 'create' In The Option "dbcreate" Of Your Data Source?

Answer :

Drops the prevailing schemaCreates the schema on startup, dropping present tables, indexes, etc. First.

Question 91. What Happens With The Db If You Have 'create-drop' In The Option "dbcreate" Of Your Data Source?

Answer :

Same as create, however also drops the tables when the utility shuts down cleanly.

Question ninety two. What Happens With The Db If You Have 'replace' In The Option "dbcreate" Of Your Data Source?

Answer :

Creates lacking tables and indexes, and updates the modern schema with out dropping any tables or data. Note that this will't properly deal with many schema modifications like column renames (you are left with the old column containing the prevailing facts).

Question ninety three. What Happens With The Db If You Have 'validate' In The Option "dbcreate" Of Your Data Source?

Answer :

Makes no adjustments in your database. Compares the configuration with the existing database schema and reports warnings.

Question 94. What Happens With The Db If You Have 'not anything/null' In The Option "dbcreate" Of Your Data Source?

Answer :

Does nothing together with your facts base

Question 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?

Answer :

Flash

Question ninety six. What Annotation Is Used For Unit Testing Of Grails Controller?

Answer :

grails.Take a look at.Mixin.TestFor

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

Answer :

you may use static hasMany property at the "one" aspect: 

elegance User 
    static hasMany = [articles: Article]

 
class Article 


Question ninety eight. How You Can Create A Bidirectional Relationships In Gorm?

Answer :

using:

static belongsTo = User

example:

class User 
    static hasMany = [articles: Article]

class Article 
    static belongsTo = User


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

Answer :

There are  approaches of specifying a one-to-one courting:

First Add an editorial belongings and the specific constraint to the User domain:

class User 
    Article article
    static constraints = 
        article particular: actual
    

class Article 
    static belongsTo = [user: User]


                        Second use the hasOne assets on the owning (User) side:
magnificence User 
    static hasOne = [article: Article]

magnificence Article 
    static belongsTo = [user: User]
                        

Question a hundred. How You Can Create Many-to-many Relationship In Gorm?

Answer :

Many-to-many relationships in Grails may be special with the aid of defining a hasMany belongings on each sides and having a belongsTo at the owned facet:

class Tag 
    static belongsTo = Post
    static hasMany = [posts: Post]

class Post 
    static hasMany = [tags: Tag]


Question a hundred and one. What Is The Use Of Flush Option In Save Operation Of A Domain?

Answer :

Saves the row straight away without any put off.

Example 

def ebook = new Book(name:"New Grails Book")
e-book.Shop(flush:true)

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

Answer :

you have to write your pluguin inside the pluguins Block/closure  within the BuildConfig.Groovy document and you need to specify if your pluguin works at run time or compilation time.

Example:

plugins 
                        build ":tomcat:7.Zero.55"
                        collect ":scaffolding:2.1.2"
                        runtime ":jquery:1.Eleven.1"


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

Answer :

with the anotation @Transactional above the class's call

Example:

import grails.Transaction.*
@Transactional
class CountryService 


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

Answer :

With the anotation @Transactional above the approach's call of the carrier

Example:

import grails.Transaction.Transactional

magnificence BookService 
@Transactional
    def updateBook() 
        // …
    


Question one hundred and five. How You Can Make A Method Not Transactional If The Whole Class Was Marked As Transactional?

Answer :

the usage of the annotation @NotTransactional above the technique's call in the service

Example:

import grails.Transaction.Transactional

@Transactional
class BookService 
    @NotTransactional
    def listBooks() 
                 Book.List()
        
    




CFG