Groovy Interview Questions

Groovy Interview Questions

Following are some of the most frequently asked Groovy interview questions in the interview, here are the answers for them.

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.

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.

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.

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.

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.

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

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.

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

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

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

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

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.

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

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.

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.

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

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.

Explain What Is Groovysh?

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

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”

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.

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

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Groovy Interview Questions"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Support


    Please leave a message and we'll get back to you soon.

    3 + 5