Thursday 4 July 2013

Groovy/Grails Sample Questions and Answers Set I

Groovy/Grails Questions & Answers - 4.1 SET I:
----------------------------------------------
1. The Grails Project uses to configure itself by
A. Convention over Configuration (ANSWER)
B. XML Based Configuration
C. applicationContext.xml
D. JSON Based Configuration
----------------------------------------------------------------------------------------------------
2. Which grails command to help to create a grails project?
A. create-project
B. create-application
C. create-grails-app
D. create-app (ANSWER)
----------------------------------------------------------------------------------------------------
3. Which following set of commands are not belongs to grails?
A. create-controller, generate-controller, generate-all
B. create-domain-class, create-service, generate-views
C. generate-domain-class, generate-service, create-views (ANSWER)
D. create-pom, create-unit-test, create-taglib
----------------------------------------------------------------------------------------------------
4. In GORM, Book and Author domains are having many-to-many relationships, then which domain notation is correct?
A. (ANSWER)
class Book {
String title
    static belongsTo = Author
    static hasMany = [authors:Author]  
}
class Author {
String name
    static hasMany = [books:Book]  
}
B.
class Book {
String title
    static belongsTo = Author    
}
class Author {
String name
    static hasMany = [books:Book]  
}
C
class Book {
String title  
    static hasMany = [authors:Author]  
}
class Author {
String name
static belongsTo = Book
}
D.
class Author {
String name
    static hasMany = [books:Book]  
}
class Book {
    String title
    static hasMany = [authors:Author]  
}
----------------------------------------------------------------------------------------------------
5. Grails supports both REST and SOAP based Web Services. To integrate SOAP into Grails which popular plugins allows you to expose
Grails services as SOAP services using a special expose property?
A. ZFire
B. WFire
C. XFire (ANSWER)
D. BFire
----------------------------------------------------------------------------------------------------
6. REST is extremely simple and just involves using plain XML or JSON as a communication medium, which combined with URL patterns that are "representational" of the underlying system and HTTP methods such as,
A. action = [REST-GET:"select", REST-PUT:"modify", REST-DELETE:"remove", REST-POST:"save"]
B. action = [GET:"show", PUT:"update", DELETE:"delete", POST:"save"] (ANSWER)
C. action = [HTTP-GET:"retrieve", HTTP-PUT:"amend", HTTP-DELETE:"remove", HTTP-POST:"save"]
D. action = [GET:"show", PUT:"update", REMOVE:"delete", CREATE:"save"]
----------------------------------------------------------------------------------------------------
7. Which set of exception is not belongs to GrailsException?
A. MissingMethodException, MissingPropertyException, RequiredPropertyMissingException
B. NullPointerException, IllegalArgumentException, IndexOutOfBoundsException (ANSWER)
C. GrailsConfigurationException, GrailsDomainException, GrailsRuntimeException
D. CompilationFailedException, InvalidPropertyException, GrailsDataSourceException
----------------------------------------------------------------------------------------------------
8. In Grails GORM is based on
A. Hibernate ORM based. (ANSWER)
B. Spring JDBC based.
C. iBatis DAO design based.
D. Toplink ORM based.
----------------------------------------------------------------------------------------------------
9. The Grails Services layer is by default built on
A. Spring Framework's AOP
B. Spring Security Framework
C. Spring Framework's Dependency Injection (ANSWER)
D. Spring Web 2.0 (MVC)
----------------------------------------------------------------------------------------------------
10. In GORM, User and Role domains are having many-to-one relationships, then which bi-directional domain notation is correct?
A.
class User {
String userName
    Role role
}
class Role {
String roleName  
}
B.
class User {
String userName    
}
class Role {
String roleName
    User user
}
C. (ANSWER)
class User {
String userName
static belongsTo = [role: Role]  
}
class Role {
String roleName
    static hasMany = [users:User]  
}
D.
class User {
String userName
static hasMany = [roles:Role]    
}
class Role {
String roleName
    static belongsTo = User
}
----------------------------------------------------------------------------------------------------
11. In GORM, MonitoringPoint and Application domains are having one-to-many relationships, then which uni-directional domain notation is correct?
A. (ANSWER)
class MonitoringPoint {
String monitoringPointName    
}
class Application {
String appName
MonitoringPoint monitoringPoint
}
B.
class MonitoringPoint {
String monitoringPointName
Application appplication
}
class Application {
String appName
MonitoringPoint monitoringPoint
}
C.
class MonitoringPoint {
String monitoringPointName
Application appplication
}
class Application {
String appName
}
D.
class MonitoringPoint {
String monitoringPointName
static hasMany = [apps:Application]
}
class Application {
String appName
static belongsTo = [monitoringPoint: MonitoringPoint]
}
----------------------------------------------------------------------------------------------------
12. Groovy is like a super version of Java. is it correct?
A. FALSE
B. TRUE (ANSWER)

----------------------------------------------------------------------------------------------------
13. Founder of Groovy / Grails (high-productivity framework) by
A. IBM
B. G2One (ANSWER)
C. SpringSource
D. VMware
----------------------------------------------------------------------------------------------------
14. A desktop framework inspired by Grails (Groovy on Rails)
A. Griffon Framework (ANSWER)
B. Play Framework
C. Spring Framework
D. Rails Framework

----------------------------------------------------------------------------------------------------
15. def list = ['Java', 'C#', 'Ruby', 'Groovy', 'Scala']
assert list.get(2) == ?
A. C#
B. Ruby (ANSWER)
C. Groovy
D. Scala
----------------------------------------------------------------------------------------------------
16. list= ['a', 'e', 'i', 'o', 'u', 'z']
use(Collections){ list.swap(2, 4) } //or: Collections.swap(list, 2, 4)
assert list == ?
A. ['a', 'e', 'u', 'o', 'i', 'z'] (ANSWER)
B. ['a', 'o', 'u', 'e', 'i', 'z']
C. ['a', 'e', 'u', 'o', 'i', 'a']
D. ['a', 'e', 'i', 'o', 'u', 'z']
------------------------------------------------------------------------------------------------------
17. def singList= Collections.singletonList('a')
assert singList == ['a']
try{
singList<< 'b';
assert 0
}
catch(e){
assert e instanceof UnsupportedOperationException
}
-- what is the result ?

A. singList == ['a']
B. singList == ['b']
C. single-element list that can't be modified. (ANSWER)
D. 0
---------------------------------------------------------------------------------------------------------
18. def set= Collections.emptySet()
assert set == [] as Set
try{
set<< 'a';
assert 0
}
catch(e){
assert e instanceof UnsupportedOperationException
}
-- what is the result ?
A. set == ['a']
B. set == []
C. 0
D. UnsupportedOperationException. (ANSWER)
--------------------------------------------------------------------------------------------------------
19. Grails-2.2.1 and Grails-2.1.1 compatible Groovy Compiler version is
A. Groovy-2.0.7 and Groovy-1.8.6 (ANS)
B. Groovy-2.1 and Groovy-2.0
C. Groovy-2.1 and Groovy-1.8
D. Groovy-2.1 and Groovy-1.7
--------------------------------------------------------------------------------------------------------
20. Which Integrated Development Environment (IDE) is introduced by VMWare to develop Grails Apps?
A. Eclipse JUNO - 4.2
B. IntelliJ IDEA
C. Groovy/Grails Tool Suite (GGTS-3.x) (ANSWER)
D. Rational Application Development (RAD-7.x)
--------------------------------------------------------------------------------------------------------
21. How do I declare and initialize a traditional array at Groovy?
A. String[] x = [ "a", "qrs" ]
B. String[] x = [ "a", "qrs" ] as String[]
C. def x = [ "a", "qrs" ] as String[]
D. All the above. (ANSWER)
--------------------------------------------------------------------------------------------------------
22. To send an error / exception message back to Groovy Server Page(s) from controller
A. flash.message (ANSWER)
B. flash.error
C. flash.exception
D. message.error
--------------------------------------------------------------------------------------------------------
23. As per Grails-2.2.1, Scaffolding feature does not currently support many-to-many relationship and hence you must write the code to manage the relationship yourself. Is this statement is true or false?
A. TRUE (ANSWER)
B. FALSE
--------------------------------------------------------------------------------------------------------
24. If you execute the following grails command from cmd prompt, The result will be a class at
grails create-domain-class com.wipro.bookstore.Book
A. grails-app/domainclasses/com/wipro/bookstore/Book.class
B. grails-app/domains/com/wipro/bookstore/Book.groovy
C. grails-app/domain/com/wipro/bookstore/Book.groovy (ANSWER)
D. grails-app/domain-class/com/wipro/bookstore/Book.class
--------------------------------------------------------------------------------------------------------
25.If you execute the following grails command from cmd prompt, The result will be a class at
grails create-service com.wipro.bookstore.Book
A. grails-app/services/com/wipro/bookstore/BookService.groovy (ANSWER)
B. grails-app/service/com/wipro/bookstore/BookService.groovy
C. grails-app/services/com/wipro/bookstore/BookService.class
D. grails-app/services/com/wipro/bookstore/Book.groovy
--------------------------------------------------------------------------------------------------------
26.If you execute the following grails command from cmd prompt, The result will be a class at
grails create-controller com.wipro.bookstore.Book
A. grails-app/controller/com/wipro/bookstore/BookController.groovy
B. grails-app/controllers/com/wipro/bookstore/BookController.groovy (ANSWER)
C. grails-app/controllers/com/wipro/bookstore/Book.class
D. grails-app/controllers/com/wipro/bookstore/BookController.class
--------------------------------------------------------------------------------------------------------
27. At the User domain class, To validate username, password String value is not blank, what we have to do at that domain class?
A.
username (blank:true)
password (blank:true)

B.
username (nullable: true)
password (nullable: true)

C.
username (nullable: false)
password (nullable: false)

D. (ANSWER)
username (blank:false)
password (blank:false)
--------------------------------------------------------------------------------------------------------
28. In the Employee domain class, To validate his email_personal & credit_card_number, website_url String value is a valid email address & credit card number, URL, what we have to do at that domain class?
A. (ANSWER)
email_personal (email:true)
credit_card_number (creditCard:true)
website_url (url:true)
B.
email_personal (email:false)
credit_card_number (creditCard:false)
website_url (url:false)
C.
email_personal (blank:false)
credit_card_number (blank:false)
website_url (blank:false)
D.
email_personal (nullable:false)
credit_card_number (nullable:false)
website_url (nullable:false)
--------------------------------------------------------------------------------------------------------
29. In Grails, The Controller by default calls index() action.  Allows you to explicitly specify the default action is "list" that should be executed if no action is specified in the URI. Please choose which one is the correct?
A. void defaultAction = "list"
B. def defaultAction = "list"
C. static defaultAction = "list" (ANSWER)
D. private defaultAction = "list"
--------------------------------------------------------------------------------------------------------
30. Which command will be used to start and stop the server of Grails App?
A. start-app & stop-app
B. run-app & stop-app (ANSWER)
C. app-run & app-stop
D. app-start & app-stop
---------------------------------------------------------------------------------------------------------
31. Grails environment has integrated by default with Tomcat server.Default port number is 8080.
To change this port into 9090 we need to add the following lines at which conf file?
grails.server.port.http = 9090
grails.server.port.https = 9090

A. Config.groovy
B. BootStrap.groovy
C. BuildConfig.groovy (ANSWER)
D. DataSource.groovy
--------------------------------------------------------------------------------------------------------
32. To add grails app's runtime dependencies and plugins, which conf file we need to use?
A. BuildConfig.groovy (ANSWER)
B. BootStrap.groovy
C. Config.groovy
D. DataSource.groovy
--------------------------------------------------------------------------------------------------------
33.To use log4j at a grails app, which conf file we need to add log4j configuration?
A. BuildConfig.groovy
B. Config.groovy (ANSWER)
C. BootStrap.groovy
D. UrlMappings.groovy
--------------------------------------------------------------------------------------------------------
34. In Grails, Which conf file we need to use to hold database setup configuration?
A. BuildConfig.groovy
B. Config.groovy
C. BootStrap.groovy
D. DataSource.groovy (ANSWER)
--------------------------------------------------------------------------------------------------------
35. In Grails, Under which grails-app folder we need to add our customized <ProjectName>Filters.groovy file configuration?
A. taglib
B. i18n
C. utils
D. conf (ANSWER)
--------------------------------------------------------------------------------------------------------
36. In Grails, To create a database tables from groovy domain classes, what environment specific settings we have to do?
 A.
 environments {
development {
dataSource {
dbCreate = "update"
}
}
 }
 B. (ANSWER)
  environments {
development {
dataSource {
dbCreate = "create"
}
}
 }
 C.
  environments {
development {
dataSource {
dbCreate = "insert"
}
}
 }
 D.
  environments {
development {
dataSource {
dbCreate = "save"
}
}
 }
--------------------------------------------------------------------------------------------------------
37. Create a Web Application Archive (WAR) file from the Grails project, which can be deployed on any Java EE compliant application server, what grails command need to use?
A. grails war (ANSWER)
B. grails create-war
C. grails generate-war
D. grails app-war
--------------------------------------------------------------------------------------------------------
38. The GrailsApplication class provides information about the conventions within Grails and access to metadata, config and the ClassLoader.
A. FALSE
B. TRUE (ANSWER)
--------------------------------------------------------------------------------------------------------
39. Which one is correct to auto generate id for MONITORING_POINT table?
A.
static mapping = {
table 'MONITORING_POINT'
id generator: 'identity', params: [identity: 'monitoringPointId'], column: 'MONITORING_POINT_ID'
}
B.
static mapping = {
table 'MONITORING_POINT'
id generator: 'sequence', params: [sequence: 'monitoringPointId'], column: 'MONITORING_POINT_ID'
}
C. All of the above (ANSWER)
D. None of the above
--------------------------------------------------------------------------------------------------------
40. Generates a controller, views, and a controller unit test for the given domain class which command you need to run?
A. grails generate-all
B. grails generate-all "*"
C. grails generate-all com.wipro.bookstore.Book (ANSWER)
D. All of the above
--------------------------------------------------------------------------------------------------------