Grails Interview Questions for Freshers/Grails Interview Questions and Answers for Freshers & Experienced

How do I call my custom environment in Grails?

Add the grails.env system property. I.e. grails -Dgrails.env=custom run-app.

Which environments are available by default in Grails?

Production (prod), Development ( dev ) and Test

What happens when you call grails bug-report?

Grails generates a dehydrated timestamped minimal zip file that can be attached to JIRA reports. One way to hydrate these into full projects is to call grails upgrade on them.

What are some things I need to be careful about when working with the Grails console?

The bootstrap files don’t get loaded. So if your database is in dbCreate = ‘create[-drop]’ mode, you might not get the same data that you would expect.The console also reloads on code change the same way that grails run-app does. So the code that you have typed in might get lost.

How do I get a hold of my Spring beans in the Grails console?

Grails console injects a ctx variable, which represents the Spring context. You can then just use ctx.getBean( ‘myServiceName’ ) to get a hold of your beans.

What is the difference between the Grails console, shell and interactive modes?

Grails interactive is interactive mode of the grails command line interface. It lets you run Gant scripts in the script runner one after another.

Grails console is a Swing-based command console similar to the Groovy console. It let’s you execute code against a full environment that has access to all your domain classes and quickly test out code that would go into controllers and services.

Grails shell is the headless version of Grails console. This is useful when you want to access and test out code in a remote SSH-based server. One of the advantages of the Grails shell is that it does not reload when domain classes change like the console does, so it is useful also for long-running scripts, although the new run-script command in Grails 1.3.6 might be better suited for those.

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

grails generate-controller "packpage"+"domain magnificence".

What Is The Command To Create A Controller?

grails create-controller "package" +"call of your area elegance"

What Is The Command To Create A Domain Class?

Grails create-domain-elegance "package deal" +"call of your area elegance".

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

grails create-app "the call of your app"

What Is Gorm?

GORM is Grails' object relational mapping (ORM) implementation. Under the hood it makes use of Hibernate (a totally famous and bendy open source ORM solution) and thanks to the dynamic nature of Groovy with its static and dynamic typing, together with the conference of Grails, there may be far much less configuration worried in creating Grails area training.

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.

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.

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.

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.

List out the differences between Groovy and Java?

* All the packages and classes in Groovy is imported by default, you do not have to use the import statement explicitly
* Unlike Java where the methods are chosen at compile time, the methods in the Groovy are chosen based on the types of arguments at runtime
* In {…} block is reserved for closures, which means that you cannot build array literals with this syntax
* Like in Java, omitting a modifier on a field does not result in a package private field
* Automatic Resource Management or ARM block from java 7 are not supported in Groovy
* Java 8 lambdas are more or less considered as anonymous inner classes, and Groovy does not support that syntax

Explain what are Bitwise Operators in Groovy?

Bitwise operators can be implemented on a BYTE or an INT and return and INT. Bitwise operators offer 4 bitwise operators

* &: bitwise “and”
* I : bitwise “or”
* A : bitwise “xor”
* ~ : bitwise negation

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

Explain what is Groovysh?

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

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

Explain how you can query in Groovy?

Let see a simple example of how Groovy calls out the query

import groovy.sql.sql

sql = Sql.newInstance ('jdbc: jtds: sqlserver://serverName/dbName-Class;domain=domainName','username','password','net.sourceforge.jtds.jdbc.driver')

sql.eachRow ('select * from tableName') {print "$${it.firstName} –" }

What do you understand by metaprogramming?

Metaprogramming is the ability of adding new methods or variables to the classes dynamically at run time. You can add methods or variables whenever and wherever you want. This is a very powerful ability. Be it the use of code production, unit tests, or anything in between, these capabilities increases the curiosity of the java developers. These are the programs that write or manipulate other programs. These are responsible for dynamic string execution. These help in exposing the internal of runtime engine to the programming codes through API’s. the meta object protocols make the program semantics explicit and extensible.

What do you mean by closures?

A closure is a short and anonymous block of code which is just used to span a few lines of code. This block of code can even be entered as a parameter in the method. Closures are anonymous in nature. Formal parameters can also be contained in closures so that it can be more useful just like methods in groovy. Closures can also refer to a variable at the time when a closure is defined. Closures can be a type of parameter for a method. Few methods provided by closure itself are listed below:

* find()
* findAll()
* any() and every()
* Collect (), etc.

What is the use of bootstrap.groovy?

Sometimes a situation occurs in which a particular task is to be carried out every time the application starts or stops.”bootstrap.groovy” is used for this particular situation. It is a simple plain groovy script which has two important closures: the “init” and “destroy” files. So, whenever the application starts or stops, these closures are called upon respectively. This “bootstrap.groovy” is present inside the grails-app/conf folder. It is used to define a code whenever the application performs any function.

Please explain the difference between the Config.groovy and BuildConfig.groovy files.

The Config.groovy file contains configuration properties and information needed when running your application. It contains properties used by your services, controllers, etc.

The BuildConfig.groovy file contains information relevant to building and deploying your application, such as repositories, jar file dependencies and war file name.

Explain the concept of externalized configuration. What is this good for?

Externalized configurations let me define other config and .properties files that don’t live within the grails-app/conf directory.

To enable this, I need to define locations for the application to look for configuration files via the grails.config.locations in Config.groovy in relation to the classpath or filesystem.

What are the best practices to be followed while developing a grails application?

Building an application using the grails framework is quite easy. But, when building it the right way we need to follow the best practices. Some of the practices followed while building a grails application are listed below:

•Controller: the controller logic should be as simple as possible. Duplication of code should be avoided.

•Service: it is the right choice for a coarse-grained code. By default, services are transactional in nature.

•Views: views should be as simple as possible. A consistent look should be maintained throughout the pages of the application.

•Internationalization: all the text messages in view should be moved to “”.

•Domain: the specific logic of the model domain should be placed in its own domain.

How can you run Scripts in Groovy?

Doing this is not a big deal. All the plain scripts are supported and compatible with Groovy. The good thing is there is no need for the programmers to declare the class which consumes additional time. At the beginning of any script, it enables the programmers to use imports. This process is very similar to using them in a class. In case you need to declare a function outside the class, you can use the command “def”

Tell one reason why more and more programmers are considering Groovy?

Well, the biggest reason is it can easily be integrated with the existing infrastructure. This makes Groovy one of the best and in fact, a good language that can be considered for any project. Due to the Java-based approach, programmers need not worry about compatibility issues and the good thing is one can easily keep up the pace in every situation.

Explain the concept of thin documentation in Groovy

Well, this is actually an issue in this Object-Oriented language. The fact is it has been seen by the programmers that Groovy doesn’t provide the detailed documentation on the project or code then run on it upon request. The documentation is limited and there is no information regarding the complex and run-time errors.

What according to you are the true reasons for the popularity of Groovy?

Well, there are certain factors that have contributed to its success. The very first thing is programmers can always make sure of a familiar syntax. This is especially for those who have a background in Java. Although Java is an old approach there is nothing wrong to say that it’s still becoming popular in every aspect. There is a very good stock of Java Libraries in Groovy and this is another important aspect for which it is quite popular. Also, it is fully Object Oriented in nature and can thus easily handle multiple tasks without any issue.

What exactly do you know about JVM?

It stands for Java Virtual Machines. They are basically regarded as one of the essential components or requirements on which Groovy works. In fact, Groovy is largely based on these machines. This is due to the fact that Groovy needs a Java-based platform to perform its task smoothly and reliably.

What Is Orm?

means item relational mapping, A simple solution is which you wrap your tables or saved strategies in training on your programming language, so that instead of writing SQL statements to interact together with your database, you operate techniques and residences of objects.It's a library or framework that assist you to map/convert your fashions in to tables for your database, It's like a mediator or an intermediate that avoid that you need to write SQL code and lets in you to interact with the DB using a programming language like groovy without should fear about write SQL code or what kind of database are you the use of, you can switch from mySql to Oracle DB enhancing only 4 strains of code, an instance of what's an ORM It's the Hibernate Framework.

What Is Grails?

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

How could you retrieve a single value from data base using Groovy?

To recover a single value from the database you can use the command

row = sql.firstRow ('select columnA, column from tableName')

println "Row: columnA = $ {row.columnA} and column = ${row.columnB}"

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)

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

What is the license for Groovy?

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

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.

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.

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)”.

What do you mean by scaffolding? How do we use it?

Scaffolding is used to generate some basic CRUD interfaces for a domain class. It includes the necessary views and some controller actions for creating, updating, reading, and deleting CRUD operations. There are basically two types of scaffolding-

<> Static scaffolding: with the help of this, controller and views can be generated to create certain interfaces using the command line.
<> Dynamic scaffolding: using dynamic scaffolding, various functions like- index, show, edit, etc. can be dynamically implemented by default by using the runtime scaffolding mechanism.

What are the best practices to be followed while developing a grails application?

Building an application using grails framework is quite easy. But, when building it the right way we need to follow the best practices. Some of the practices followed while building a grails application are listed below:

* Controller: the controller logic should be as simple as possible. Duplication of code should be avoided.
* Service: it is the right choice for a coarse-grained code. By default, services are transactional in nature.
* Views: views should be as simple as possible. A consistent look should be maintained throughout the pages of the application.
* Internationalization: all the text messages in view should be moved to “”.
* Domain: the specific logic of the model domain should be placed in its own domain.

What do you understand by the concept of thin documentation in Groovy?

Thin documentation refers to a lack of proper or detailed documentation. This issue is with many Object-Oriented languages. Groovy programmers often complain about a lack of detailed documentation on the project or code. The documentation is limited in scope, and there is no information or very little information regarding the complex processes and run-time errors.

How do I edit the web.xml file of my grails application?

First, I need to generate the template files via grails install-templates. The web.xml template will be under src/templates/war directory.

Alternatively, I could also create a plugin and use the doWithWebDescriptor method to add or remove nodes from my web.xml file.

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.

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

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

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.

R4R Team
R4R provides Grails Freshers questions and answers (Grails Interview Questions and Answers) .The questions on website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Grails Interview Questions for Freshers,Grails Freshers & Experienced Interview Questions and Answers,Grails Objetive choice questions and answers,Grails Multiple choice questions and answers,Grails objective, Grails questions , Grails answers,Grails MCQs questions and answers Java, C ,C++, ASP, C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Grails fresher interview questions ,Grails Experienced interview questions,Grails fresher interview questions and answers ,Grails Experienced interview questions and answers,tricky Grails queries for interview pdf,complex Grails for practice with answers,Grails for practice with answers You can search job and get offer latters by studing .learn in easy ways .