La idea de la charla es dar un comparación entre los diversos features de ambos lenguajes como:
* Lambdas/Closures
* Method references
* Default Methods / Traits
* Soporte de APIs de Java 8 en Groovy
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
javerosmx-2015-marzo-groovy-java8-comparison
1. Groovy & Java 8
A very simple comparison
@ JaverosMX, Mexico City
30/Marzo/2015Domingo Suárez Torres (@domix)
2. Agenda
• Background
• A little bit about Groovy
• Why is important to upgrade to Java 8
• Comparison
• Very small :’(
3. Groovy, just a little
• Optionally typed & dynamic language for the
JVM
• Static-typing and static compilation capabilities
• Scripting capabilities, Domain-Specific
Language authoring, runtime and compile-time
meta-programming and functional programming
6. Java 8 matters
• Java 7 EOL. April 2015
• Java 6 < go figure.
• “Brand new” techniques, patterns, paradigms. Built in the language.
• Very soon libraries and frameworks will adopt those improvements.
• Enhancements
• Nashorn
• Invoke-dynamic
• Java 8 arrived late to the party. Better late than never.
7. Java 8 features
• New Syntax
• Stream API
• Profiles
• JavaFX
• Date/Time API
• Nashorn
• Pack200
• JDBC
• Concurrency
• JAXP
• Hotspot
• Java Mission Control
12. Code as data
• Interfaces with one method (functional interface)
• Single Abstract Method interfaces (SAM Interfaces)
• Inner classes are annoying due verbosity.
• Java 8 Lambda Expressions, Groovy Closures.
• JVM functions became almost first-class
citizens.
17. Groovy Closures
• Since 2003.
• Is an open, anonymous, block of code that can take
arguments.
• Return a value and be assigned to a variable.
• A closure may reference variables declared in its
surrounding scope.
• Can also contain free variables which are defined outside
of its surrounding scope. In opposition to the formal
definition of a closure.
32. java.util.Stream
• Represents a sequence of elements on which one or
more operations can be performed.
• Stream operations are either intermediate or terminal.
• While terminal operations return a result of a certain type,
intermediate operations return the stream itself so you
can chain multiple method calls in a row.
• Streams are created on a source (Collection)
• Stream operations can either be executed sequential or
parallel.
37. Groovy GDK
• Groovy add lots of enhancements into the
standard JDK
• Groovy “injects” additional methods on the
standard Java libraries
• GDK adds syntactic sugar to Java APIs for
better and easier usage.
39. GDK and Java 8
• Some GDK facilities will be deprecated in favor
of Stream
• Stream is more efficient and performant
• Groovy will focus in better integration with Java 8
enhancements
41. java.util.Optional<T>
• NPE is awkward.
• A optional is a container object which may or
may not contain a non-null value.
• Additional methods that depend on the
presence or absence of a contained value are
provided, such as orElse() (return a default value
if value not present) and ifPresent() (execute a
block of code if the value is present).
45. Groovy Truth
• Everything that’s null, empty, zero-sized, equal to
zero is false. Otherwise is true
• Groovy Truth is quite simple: just implement a
custom asBoolean() method.