Groovy Learning Summary

Source: Internet
Author: User
Tags groovy script

First thanks to the Wu Yi of Groovy in action Part 1, and thanks to the author, translator, and uploader of the groovy Starter Classic, as well as to the audience who uploaded the PDF, and finally thanks to Groovy's father James Strachan

This article is based on groovy 1.8.

======== Split Line started in 2014-12-1 ========

1,groovy Start Running

Groovy Definitions and Features:

is an agile dynamic language based on a Java virtual machine.
Built on the powerful Java language and added many features learned from languages such as Python,ruby and Smalltalk.
Provides Java developers with modern, most popular programming language features and low learning costs (almost 0).
Support DSL (Domain specific languages domain definition language) and other concise syntax to make your code easier to read and maintain.
Goovy has processing native types, object-oriented, and an ant DSL, making it very easy to create shell scripts.
The developer's efficiency is greatly improved by the reduction of Framework code when developing Web,gui, database or console programs.
Unit Tests and simulations (objects) are supported to simplify testing.
Seamlessly integrates all existing Java objects and class libraries.
Compile directly into Java bytecode, so you can use groovy anywhere you use Java.
For example, using the Groovy console, enter the following code to output all the file names (recursion) in the current directory:
Groovy-e "New File ('. '). Eachfilerecurse {println It} "//-e Direct execution
Compared to Java classes with the same functionality, efficiency is seen.

3 Ways to run Groovy:

    1. Groovysh: script command line REPL
    2. Groovyconsole: Open GUI interface, above is the script editing area, the lower part is output, run shortcut key CTRL + R
    3. Groovy: Execute script file with parameters

For example, execute the groovy script:

Fibonacci.groovycurrent = 1 Next = 1 10.times {//Loop 10 times Print current + ' Newcurrent = next next = next + cur Rent = newcurrent} println "

Groovy Fibonacci===>1 1 2 3 5 8 13 21 34 55
2, grammarBasis


#!/usr/bin/groovy/*  Multiline Comment */def y = 1; assert y = = 1//  single-line comment assert current line y.equal (1), non-reference





Groovy Learning Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.