Groovy getting started notes

Source: Internet
Author: User

I. Preparations• Download-go to http://yy.codehaus.org/download. currently, the latest version is groovy plugin, Which is decompressed to a directory, for example, C: \ java \ groovy-1.8.6-add an environment variable GROOVY_HOME in the system environment variable, the value is the decompressed directory C: \ java \ groovy-1.8.6GROOVY-Modify the environment variable PATH, add % policy_home % \ bin to the variable value-open cmd or shell, run groovy-v, the version information indicates that the Groovy installation is complete.

Run yysh To Go To The Groovy console. The groovyConsole opens the GUI console.

• Plug-in-Groovy Eclipse plug-in installation address is plugin/

After installation, Eclipse will support Groovy in multiple places

 

 

Ii. Syntax features

• The Groovy syntax is compatible with the Java syntax, so the features of the columns here are different from those of Java-variable method declaration: you do not need to specify the type to define variables, use the def keyword, you can omit the semicolon after each row. The default access range is public. -Note: it is the same as java annotations. In addition,/usr/bin/groovy can only be used in the first line. Locate the groovy STARTUP script for linux. -Ignore the package prefix, Parentheses, and semicolons. -More concise GroovyBean: you do not need to write the getter setter method in GroovyBean. -Optional return statement: the return keyword is optional. If return is ignored, the return value is the return result of the final expression. -Automatic Import class:

-Assertions: assert keyword. -Data Type: everything in Groovy is an object, and numbers are also objects. -Use collection classes: 1) list: allows you to change the size of the list at run time. objects stored in the list are not limited by types. You can index the list by the number of objects beyond the list range, to change the size of the list. 2) map: specific operator def map = "z" (Note: num contains 26 letters from a to z)-closure-control structure: 1) such as if-else, while, switch, and try-catch-finally, which is the same as the Structure Control of java. 2) in the condition, null is processed as false, not-null is processed as true, and the for loop has a tag for (I in x) {body, x can be any object, and groovy knows how to iterate it, such as Iterator/enumeration/collection/range/map/any object. 3) whether to declare an exception during method declaration is optional, even if it is an exception of the check. -Regular Expression: regex search operator "= ~";
Regex matching operator "= ~";
Regex pattern operator ~ String;

-Groovy is dynamic: java generates groovy classes at runtime.

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.