Groovy

Apache Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax

Install

   1 wget https://dl.bintray.com/groovy/maven/apache-groovy-binary-3.0.3.zip
   2 cp apache-groovy-binary-3.0.3.zip ~/
   3 cd  ~/
   4 unzip  apache-groovy-binary-3.0.3.zip 
   5 nano ~/.bashrc
   6 # export GROOVY_HOME=$HOME/groovy-3.0.3
   7 # PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user/jdk-11.0.2/bin:/home/user/scripts
   8 # PATH=$PATH:/opt/mssql-tools/bin/:$GROOVY_HOME/bin
   9 # export PATH
  10 . ~/.bashrc 
  11 groovysh
  12 # print("aaa")
  13 groovyConsole

groovyc - compiler

   1 class X{
   2   int amount
   3 }
   4 
   5 def x = new X()
   6 x.amount = 1
   7 println("${x.amount}")

   1 groovyc MyClass.groovy
   2 java -cp . -jar $GROOVY_HOME/lib/groovy-3.0.3.jar   MyClass
   3 java -jar $GROOVY_HOME/lib/groovy-3.0.3.jar   MyClass

swing - groovy

   1 import groovy.swing.SwingBuilder
   2 import java.awt.BorderLayout as BL
   3 
   4 count = 0
   5 
   6 def actionPerformedFn(){
   7   count++; 
   8   textlabel.text = "Clicked ${count} time(s)."
   9   println "clicked"
  10 }
  11 
  12 def quitFn(){
  13   System.exit(0) 
  14 }
  15 
  16 new SwingBuilder().edt {
  17   frame(title: 'Frame', size: [300, 300], show: true) {
  18     borderLayout()
  19     textlabel = label(text: 'Click the button!', constraints: BL.NORTH)
  20     button(text:'Click Me', actionPerformed: {actionPerformedFn()}, constraints:BL.WEST)
  21     button(text:'Quit', actionPerformed: {quitFn()}, constraints:BL.EAST)
  22   }
  23 }

   1 groovyc swing.groovy 
   2 java -cp .:$GROOVY_HOME/lib/groovy-3.0.3.jar:$GROOVY_HOME/lib/groovy-swing-3.0.3.jar swing

Groovy (last edited 2023-05-26 14:43:08 by 127)