Sample Grails Application to  get an overview............

Grails is an open source web application framework that uses the Groovy programming language (which is in turn based on the Java platform). It is intended to be a high-productivity framework by following the "coding by convention" paradigm, providing a stand-alone development environment and hiding much of the configuration detail from the developer.
Grails was previously known as 'Groovy on Rails'; in March 2006 that name was dropped in response to a request by David Heinemeier Hansson, founder of the Ruby on Rails framework. Work began in July 2005, with the 0.1 release on March 29, 2006 and the 1.0 release announced on February 18, 2008.
G2One - The Groovy Grails Company - was acquired by SpringSource in November, 2008, and it was later acquired by VMware.

Grails
Grails logo.png
Developer(s)Graeme Rocher
Initial releaseJuly, 2005
Stable release2.4.0 / May 21, 2014
Written inGroovy
Operating systemCross-platform
PlatformCross-platform (JVM)
TypeWeb application framework
LicenseApache License 2.0
Websitegrails.org

Overview

Grails was developed to address a number of goals:
  • Provide a web framework for the Java platform.
  • Re-use existing Java technologies such as Hibernate and Spring under a single interface
  • Offer a consistent development framework.
  • Offer documentation for key portions of the framework:
  • Provide sample applications that demonstrate the framework.
  • Provide a complete development mode, including a web server and automatic reload of resources.

High productivity

Grails has three properties that differentiate it from traditional Java web frameworks:
  • No XML configuration
  • Ready-to-use development environment
  • Functionality available through mixins
_________________________________________________________________________________
Example sample program:
Create a sample app by clicking 
File->new-> Groovy Project->



package sample 

class Testclass {
static void main(args){
def a = 'Asha Anusha'
a = new Object()
a = 10
println a
println ".............................................."
def firstname='Anu'
def lastname='Anusha'
def d=3
def b=6

println  "${firstname},${lastname}"
println  '${firstname},${lastname}'
println "..................How to print............................."
println  "a+b=${a+b}"
println  'a+b=${a+b}'
println "....................Lists..........................."
def list =[1,2,3,4,5 ]
println  "Sample List=${list}"
def myList = [10, "John", new Integer(5), new Double(7.6d)]
println  "Can add any type in MyList=${myList}"
println ".....................Appending vales.........................."
def alist = [10, 9, 8]
alist << 7
alist << 6
println  "Appending into List=${alist}"
println ".............Working with list................................."
def alist1 = ["Hai", "Welcome", "To","Grails"]
println "List sample=${alist1[1]}, ${alist1[2]}"
println "To get the size we can use size operator=${alist.size()}"
def alist2 = [10,11,12,13,14,15,16,17,18,19,20]
println "To get subset of a list given a criteria(this will give even numbers)=${alist.findAll{it % 2 == 0}}"
println "to multiply each nuber with 10=${alist2.collect{it * 10}}"
def alistsamp = ["Hai", "Welcome", "To","Grails"]
println alistsamp*.length()
println ".............Working with Map................................."
def emptyMap = [:]
def mapWithValues = [Language:'Java',  Script:'Java Script']
def alist4 = [Language:'Java',  Script:'Java Script']
alist4['car'] = 'Sedan'
alist4.put('book', 'Novels')
alist4 << [pet:'Dog']
println alist4['Language']
println alist4.'Script'
println alist4.get('car')
println alist4.get('book')
println alist4.get('pet')
println "..............How to print mltiple times........................."
5.times {
println "Hello ! Welcome to My Blog!!"
}
println ".................Looping through items of a list......................"
['cat', 'dog', 'hamster'].each { name ->
println name
}
println "..............Replace for loop with a number range ........................."
(6..11).each { number ->
println number
}
println "..............Loop Through Map........................."
[fruit:'Apple', veggie:'Carrot', car:'Sedan'].each { key, value ->
println "${key} = ${value}"
}
}

}
 To run the above program 
click on :: run as-> Groovy Script

OutPut:

10
...............................................
Anu,Anusha
${firstname},${lastname}
...............................................
a+b=16
a+b=${a+b}
...............................................
Sample List=[1, 2, 3, 4, 5]
Can add any type in MyList=[10, John, 5, 7.6]
...............................................
Appending into List=[10, 9, 8, 7, 6]
.............Working with list.................................
List sample=Welcome, To
To get the size we can use size operator=5
To get subset of a list given a criteria(this will give even numbers)=[10, 8, 6]
to multiply each nuber with 10=[100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]
[3, 7, 2, 6]
.............Working with Map.................................
Java
Java Script
Sedan
Novels
Dog
..............How to print mltiple times.........................
Hello ! Welcome to My Blog!!
Hello ! Welcome to My Blog!!
Hello ! Welcome to My Blog!!
Hello ! Welcome to My Blog!!
Hello ! Welcome to My Blog!!
.................Looping through items of a list......................
cat
dog
hamster
..............Replace for loop with a number range .........................
6
7
8
9
10
11
..............Loop Through Map.........................
fruit = Apple
veggie = Carrot
car = Sedan

No comments:

Post a Comment