-
Notifications
You must be signed in to change notification settings - Fork 39
Home
Safari Books Online, https://www.safaribooksonline.com/
Ken Kousen
ken.kousen@kousenit.com
@kenkousen
newsletter
This document is for notes that come up during class. It’s also an easy way to share code and other materials.
-
GitHub Repository: https://github.com/kousen/IntroGroovy
-
HTML materials: http://www.kousenit.com/groovy/
-
Groovy Home Page: http://groovy-lang.org/
-
Groovy API: http://groovy-lang.org/api.html
-
Groovy JDK: http://groovy-lang.org/gdk.html
-
Java 8 doc: https://docs.oracle.com/javase/8/docs/api/
-
Java 11 doc: https://docs.oracle.com/en/java/javase/11/docs/api/index.html
Groovy plugin for Eclipse: https://github.com/groovy/groovy-eclipse/wiki#releases
Non-Java languages on the JVM:
-
Groovy, www.groovy-lang.org
-
Scala
-
Clojure
-
Kotlin, www.kotlinlang.org
Groovy is a compiled language, even though we will write some "scripts"
Groovy Slack channel: http://groovycommunity.com/
All we need for setup is a Java SDK (JDK) version 1.8 or above and a Groovy installation
Version number summary:
-
Current stable version in the 3.0 line is 3.0.4
-
Current stable version in the 2.5 line is 2.5.12
Groovy 3:
-
Significant compiler redesign → Parrot Parser, support all Java 8 syntax
-
Requires Java 8 as the minimum Java version
- IntelliJ
-
Import the
build.gradle
file-
Use
Open
if an existing project is open, orImport
otherwise -
Navigate to the
build.gradle
file in the root of the project -
Accept all the defaults in the Import wizard
-
- Eclipse
-
Create an Eclipse project and import it
-
From a command prompt, execute
>gradlew cleanEclipse eclipse
-
Use File → Open → General → Existing Projects Into Workspace → navigate to the root of the project and select it
-
-
static typing → types are known at compile time
-
Java, Scala, Kotlin
-
-
dynamic typing → types are inferred at run time
-
JavaScript, Python, Clojure
-
-
Groovy → optional typing
-
if you know the type (or care), specify it
-
if you don’t know or don’t care, use
def
-
-
Normal practice suggests you use def less than 10% of the time
-
Most of the time, "if you’re typing and know the type, type it" (pun intended) — Dierk Koenig
-
It’s nice to have def available when you need it
-
Wait, isn’t def just an Object reference?
-
Yes, but Groovy also has Duck typing (term from Ruby) "If it walks like a duck and it quacks like a duck, it’s a duck"
In Java, if I use an Object
ref, I can only invoke Object
methods (unless I cast)
In Groovy, with a def
type, I can invoke any method (or property) I like
-
if it’s there at runtime, we’re fine
-
Otherwise we’ll throw a
MissingMethodException
-
Groovy in Action, 2nd edition, Koenig, King, et al (Manning) https://www.safaribooksonline.com/library/view/groovy-in-action/9781935182443/
-
Making Java Groovy, me, (Manning) https://www.safaribooksonline.com/library/view/making-java-groovy/9781935182948/
-
Learning Path Groovy: https://www.safaribooksonline.com/library/view/learning-path-groovy/9781491958148/
-
Groovy Programming Fundamentals https://www.safaribooksonline.com/library/view/groovy-programming-fundamentals/9781491926253/
-
Practical Groovy Programming https://www.safaribooksonline.com/library/view/practical-groovy-programming/9781491930908/
-
Mastering Groovy Programming https://www.safaribooksonline.com/library/view/mastering-groovy-programming/9781491930915/