[WIP]Groovy Tutorial

Created: 2022/12/26

 My feeling at this moment is just someting like these emojis: 😂😎😌

Overview
   

Features of Groovy

Groovy has the following features −

  • Support for both static and dynamic typing.
  • Support for operator overloading.
  • Native syntax for lists and associative arrays.
  • Native support for regular expressions.
  • Native support for various markup languages such as XML and HTML.
  • Groovy is simple for Java developers since the syntax for Java and Groovy are very similar.
  • You can use existing Java libraries.
  • Groovy extends the java.lang.Object.
   
   
   
   
   
Environment
 

  

brew install groovy

 

 

   
Basic Syntax
   
Import Statement

By default, Groovy includes the following libraries in your code, so you don’t need to explicitly import them. 

import java.lang.* 
import java.util.* 
import java.io.* 
import java.net.* 

import groovy.lang.* 
import groovy.util.* 

import java.math.BigInteger 
import java.math.BigDecimal

 

 

Comment

  

// single line comment

/*
multiple lines comment
*/

 

 

Semicolons

 not mandatory

Identifiers 

Identifiers are used to define variables, functions or other user defined variables. Identifiers start with a letter,

a dollar or an underscore. They cannot start with a number. Here are some examples of valid identifiers 

   
Data Types
Built-in Data Types   
byte
This is used to represent a byte value. An example is 2.
short This is used to represent a short number. An example is 10.
int This is used to represent whole numbers. An example is 1234.
long This is used to represent a long number. An example is 10000090.
float This is used to represent 32-bit floating point numbers. An example is 12.34.
double This is used to represent 64-bit floating point numbers which are longer decimal number representations which may be required at times. An example is 12.3456565.
char This defines a single character literal. An example is ‘a’.
Boolean This represents a Boolean value which can either be true or false.
String These are text literals which are represented in the form of chain of characters. For example “Hello World”.
   
Class Numeric 

  

java.lang.Byte
java.lang.Short
java.lang.Integer
java.lang.Long
java.lang.Float
java.lang.Double

In addition, the following classes can be used for supporting arbitrary precision arithmetic

java.math.BigInteger
java.math.BigDecimal

 

 

   
   
   
   
Variables
   
   
   
   
   
   
Operators
   
   
   
   
   
   
Loops
   
   
   
   
   
   
Decision Making
   
   
   
   
   
   
Methods
   
   
   
   
   
   
File I/O
   
   
   
   
   
   
Optionals
   
   
   
   
   
   
Numbers
   
   
   
   
   
   
Strings
   
   
   
   
   
   
Ranges
   
   
   
   
   
   
Lists
   
   
   
   
   
   
Maps
   
   
   
   
   
   
Dates&Times
   
   
   
   
   
   
Regular Expressions
   
   
   
   
   
   
Exception Handling
   
   
   
   
   
   
Obeject Oriented
   
   
   
   
   
   
Generics
   
   
   
   
   
   
Traits
   
   
   
   
   
   
Closures
   
   
   
   
   
   
Annotations
   
   
   
   
   
   
XML
   
   
   
   
   
   
JMX
   
   
   
   
   
   
JSON
   
   
   
   
   
   
DSLS
   
   
   
   
   
   
Database
   
   
   
   
   
   
Builders
   
   
   
   
   
   
Commind Line
   
   
   
   
   
   
Unit Test
   
   
   
   
   
   
Template Engine
   
   
   
   
   
   
Meta Object Programming
   
   
   
   
   
   
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章