Groovy is a programming language for the Java Platform. Similar to other languages like Perl, Python it is also a both static and dynamic language. It is easy to use and integrate with Java. Java developers are using this language more and became popular for its general purpose syntax. It is no similar to other languages but has the flexibility, effective and efficient in using it. Java developers use it to develop projects faster and easier. Good knowledge on Groovy language will boost your confidence. Follow our Wisdomjobs page for Groovy (programming language) interview questions and answers page to get through your job interview successfully in first attempt. Interview questions are exclusively designed for job seekers to assist them in clearing interviews.
Question 1. Explain What Is Groovy?
Answer :
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.
Question 2. What Are The Dependencies For Groovy?
Answer :
As well as Java 1.4 and the Groovy jar we also depend at runtime on the ASM library.
Question 3. Mention What Relational Operators Is Used For In Groovy?
Answer :
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.
Answer :
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.
Answer :
Question 6. What Is The Licence For Groovy?
Answer :
Groovy is open source using a BSD / Apache style licence
Question 7. When “propertymissing (string)” Method Is Called?
Answer :
The “propertyMissing (String)” method is called when no getter method for a given property can be detected by the Groovy runtime.
Question 8. How Can I Add Stuff To The Classpath When Running Things In Groovysh Or Groovy?
Answer :
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.
Question 9. What Is The Limitation Of Groovy?
Answer :
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 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.
Question 11. Explain What Does The Jsonslurper Class Indicates?
Answer :
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.
Question 12. Explain How Scripts Are Run In Groovy?
Answer :
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.
Question 13. Explain The Role Of Grape Dependency In Groovy?
Answer :
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.
Question 14. Mention What Are Some Features Does Groovy Jdk Offers?
Answer :
Groovy has added new methods compare to old version like
Question 15. Explain Groovydoc Comment?
Answer :
Like multiline comments, GroovyDoc comments are multiline but it starts with a /** and end with */. Those comments are related with
Question 16. Mention What Is The Role Of Closure And Listeners In Groovy?
Answer :
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.
Question 17. Explain What Is Groovysh?
Answer :
Groovysh is a command line application that enables an easy access to evaluate Groovy expressions, define classes and run experiments.
Answer :
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.
Question 19. Explain How You Can Include A Groovy Script In Another Groovy?
Answer :
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”))
Question 20. Mention What Is The License For Groovy?
Answer :
Groovy depend at runtime on the ASM library as well as Java 1.4 and the Groovy jar.
Question 21. Explain How Groovy String Is Expressed?
Answer :
Groovy string is referred as Gstring.
Question 22. Explain What Is Expandometaclass In Groovy?
Answer :
ExpandoMetaClass is used to add methods, properties, static methods and constructors. Expandoclass does not inherited by default; you have to call ExpandoMetaClass.enableGlobally().
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 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).
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.
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.
Question 26. What Is The Command To Create A New Application In Grails?
Answer :
grails create-app "the name of your app"
Question 27. What Is The Command To Run A Grails Application?
Answer :
grails run-app
Question 28. What Is The Command To Create A Domain Class?
Answer :
grails create-domain-class "packpage" +"name of your domain class"
Question 29. What Is The Command To Create A Controller?
Answer :
grails create-controller "packpage" +"name of your domain class"
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 war
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
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-views "packpage"+"domain class"
Answer :
grails generate-all "packpage"+"domain class"
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 test-app --unit
Question 41. What Is The Command To Test Your Application For Integration Test Only?
Answer :
grails test-app --integration
Question 42. What Is The Command To Rerun Test In Your Application?
Answer :
grails test-app --rerun
Question 43. What Is The Command To See Your Grails Version?
Answer :
grails -version
Question 44. What Is The Command To Create The Unit Test Of A Domain Class?
Answer :
grails create-unit-test "packpage"+"domain class"
Question 45. What Is The Command To Create The Integration Test Of A Domain Class?
Answer :
grails create-integration-test "packpage"+"domain class"
Question 46. What Is Data Binding?
Answer :
It's the act of binding incoming request parameters on to the properties of an object.
Question 47. Where Do You Setup Your Db , Hibernate Version And Environments?
Answer :
DataSource.groovy
Answer :
BuildConfing.groovy
Question 49. 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.
Answer :
In your domain class:
static transient['cant save this']
Question 51. What Is Methaprogramming?
Answer :
It's the groovy ability to add new methods or variables to classes dynamically at run time, and without torching the code.
Question 52. Could You Give Me An Example Of Methaprogramming In Grails?
Answer :
The dynamic finders in the domains class.
Question 53. What Type Of Looking Is By Default In Grails Optimistic Or Pessimist Looking?
Answer :
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.
Question 54. 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.
Question 55. How Do You Use Pessimist Looking In A Domain Class?
Answer :
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
}
}
Question 56. 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 57. What Is Dynamic Finders?
Answer :
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%")
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: 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
}
}
Answer :
grails-app/conf/UrlMappings.groovy.
Question 61. How Do You Secure Your Grails Application?
Answer :
Use Grails Filter
Answer :
Edit your Config.groovy file. Find the line with:
hibernate = "off"
and replace it with:
hibernate.SQL="trace,stdout"
hibernate.type="trace,stdout"
Question 63. How Do You Render A Domain Object As Xml Or Json?
Answer :
render Book.list(object) as JSON
render Book.get(object) as XML
Question 64. How Do You Access Servlet Attributes From Controller?
Answer :
servletContext
servletContext is available in controller.
Question 65. What Is Javascript Tag In Gsp?
Answer :
Includes JavaScript libraries and scripts as well as providing a shorthand for inline JavaScript.
Question 66. 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 68. What Option Do You Use To Create War File For Specific Environment?
Answer :
-Dgrails.env
Example : grails -Dgrails.env=dev war
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-service "packpage"+"service name"
Question 71. What Is The Command To Create A Tag Library In Grails?
Answer :
grails create-tag-library+ "packpage"+"name"
Question 72. What Is Are The Closures In Groovy?
Answer :
A closure in Groovy is an open, anonymous, block of code that can take arguments, return a value and be assigned to a variable.
Question 73. How Do You Inject A Service In Your Controller?
Answer :
def taskService
Question 74. 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 :
in your controller:
def scaffold=true or def scaffold="the name of your domain class"
Question 77. What Is A Template In Grails?
Answer :
It's a reusable part of a view that can be used to render a small part of a view.
Question 78. What Is A Grails Pluguin?
Answer :
It's a bundle/set of functionality to a desired propose that can be installed in your grails application.
Question 79. 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 compile
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 :
in your domain class:
class Person {
…
static mapping = {
table 'people'///this is the mapping of the domain in the table
}
}
Answer :
class Person {
String firstName
static mapping = {
table 'people'
firstName column: 'First_Name' ///this is the mapping of the columm in the table
}
}
Question 84. What Is Sitemesh?
Answer :
It's a HTML templating framework
Question 85. How You Can Validate Your Domain Classes Against Invalid Data?
Answer :
using : 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 can customize how grails maps the URLs in your application
Question 87. What Is The Command To Run Your App In A Custom Environment?
Answer :
grails -Dgrails.env="your custom enviroment" run-app
Answer :
using the line in 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', 'update', 'validate' and ' null '
Answer :
Drops the existing schemaCreates the schema on startup, dropping existing tables, indexes, etc. first.
Answer :
Same as create, but also drops the tables when the application shuts down cleanly.
Answer :
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).
Answer :
Makes no changes to your database. Compares the configuration with the existing database schema and reports warnings.
Answer :
Does nothing with your data base
Answer :
Flash
Question 96. What Annotation Is Used For Unit Testing Of Grails Controller?
Answer :
grails.test.mixin.TestFor
Question 97. How You Can Create A One-to-many Relationship In Gorm?
Answer :
you can use static hasMany property at the "one" side:
class User {
static hasMany = [articles: Article]
}
class Article {
}
Question 98. 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 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]
}
Question 100. How You Can Create Many-to-many Relationship In Gorm?
Answer :
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]
}
Question 101. 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)
Question 102. How Can You Install A Pluguin In Your Grails Application?
Answer :
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"
}
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 name
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 method's name of the service
Example:
import grails.transaction.Transactional
class BookService {
@Transactional
def updateBook() {
// …
}
}
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()
}
}
Groovy (programming language) Related Tutorials |
|
---|---|
Adv Java Tutorial | Selenium Tutorial |
Hibernate Tutorial | Spring MVC Framework Tutorial |
Agile Methodology Tutorial |
Groovy (programming language) Related Practice Tests |
|
---|---|
Adv Java Practice Tests | Selenium Practice Tests |
Hibernate Practice Tests | Java applet Practice Tests |
Amazon Web Services (AWS) Practice Tests | Adobe Analytics Practice Tests |
Spring MVC Framework Practice Tests | Agile Scrum Master Practice Tests |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.