Groovy (language)

Groovy is the name of a Computer programming language directed object intended for the platform Java.
Il constitutes an alternative to the Java language for this platform and is inspired by Python, Ruby and Smalltalk. It is the object of specification JSR 241.

Groovy uses a syntax very close to Java with accodances and is directly compiled, either with dynamically stolen, or classically with a compiler in Bytecode.

Groovy is integrated quite naturally with the ecosystem Java bus from the point of view of JVM, it does not present a difference: it is Bytecode. It can thus

  • use the libraries Java;
  • to be used in classes Java.

Main features of the language

Groovy has certain characteristics which differentiates it from the standard Java
  • static Typing and dynamic Typing;

  • lists, maps, and regular expressions nativement supported;
  • closings or closures;
  • Overload of the operators.

Comparison between Java and Groovy

Here a comparison of Java and Groovy:

Standard Java (Java 5+) class Filter { public static void hand (String args) { List shorts = new ArrayList (); for (String item: Arrays.asList (" Rod" , " Carlos" , " Chris")) yew (item.length () <= 4) shorts.add (item); for (String item: shorts) System.out.println (item); } }

Groovy list = " Carlos" , " Chris" shorts = list.findAll {it.size () <= 4} shorts.each { println it }

Language of beaconing (XML, HTML,…)

One of the notable characteristics of Groovy is its native support of the languages of beaconing such as XML and HTML. This support makes it possible to define and handle by programming several type of structure with a common syntax.

Example:

this Groovy code… importation groovy.xml.MarkupBuilder def myXMLDoc = new MarkupBuilder () myXMLDoc.workbook { worksheet (caption: " Employees") { row (fname=" John" , lname=" McDoe") row (fname=" Nancy" , lname=" Davolio") } worksheet (caption: " Products") { row (name=" Veeblefeetzer" , id=" sku34510") row (name=" Plum Links Zappa" , id=" sku3a550") } } println myXMLDoc

… produced following contents XML:

Other examples

; Hello World print " hello word"

def name=' World'; println " Hello $name! "

; To post an ordered list of names transformed into Capital letter def names = “John”, “Jill” println names.collect {it.toUpperCase ()} .sort ()

; To post the first seven successive squares of 2 def num = 2G 7.times { println " $num" num *= num } 2 4 16 256 65536 4294967296 18446744073709551616

; To define classes user class Persson { String name String givenname int old String sex }

class To use extends Persson { String userid String email }

def titi = new To use (name: “titi”) titi.userid = “titi1412” titi.email = “titi@acme.org” titi.age = 40

def rominet = new Persson (name: “rominet”, old: 40, sex: “uhum”) println " He $ {rominet.name}, here $ {titi.name}, an old buddy of promotion. Write me on $ {titi.email}! "

External bonds

  • Groovy
  • a page of article devoteds to in Groovy

Random links:Partizan Belgrade (male volley ball) | Arumana No Kiseki | Fabrice Borer | Honda VF | County of Sheqi | Métal_de_Glam