Groovy Intro

1,070 views

Published on

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

Groovy Intro

  1. 1. Groovy for Java experts V á clav Pech Software Developer and Product Evangelist JetBrains, Inc.
  2. 2. Properties
  3. 3. Closures
  4. 4. Closures – implicit parameter
  5. 5. Iterations
  6. 6. GDK = JDK + FUN <ul><li>java.util.Collection </li></ul><ul><ul><li>each(), find(), join(), min(), max() … </li></ul></ul><ul><li>java.lang.Object </li></ul><ul><ul><li>any(), every(), print(), invokeMethod(), … </li></ul></ul><ul><li>java.lang.Number </li></ul><ul><ul><li>plus(), minus(), power(), upto(), times(), … </li></ul></ul><ul><li>… </li></ul>
  7. 7. Some operators <ul><li>[‘ Java ’, ‘ Groovy ’]*.toUpperCase() </li></ul><ul><li>customer ? .shippingAddress ? .street </li></ul><ul><li>return user.locale ?: defaultLocale </li></ul>
  8. 8. Syntax enhancements <ul><li>Dynamic (duck) typing – optional! </li></ul><ul><li>GDK </li></ul><ul><li>Syntax enhancements </li></ul><ul><ul><li>Properties </li></ul></ul><ul><ul><li>Closures </li></ul></ul><ul><ul><li>Named parameters </li></ul></ul><ul><ul><li>Collections and maps </li></ul></ul><ul><ul><li>Operator overloading </li></ul></ul><ul><ul><li>… </li></ul></ul>
  9. 9. Enjoy writing tests <ul><li>For both Java and Groovy </li></ul><ul><li>Run with Ant, Maven, IDE, … </li></ul><ul><li>Integrated JUnit support </li></ul><ul><ul><ul><li>assert…(), shouldFail(), … </li></ul></ul></ul><ul><li>Relaxed typing </li></ul><ul><li>Easy mocking </li></ul>
  10. 10. Big Boy Toys <ul><li>Scripting </li></ul><ul><li>Builders </li></ul><ul><li>Domain Specific Languages </li></ul><ul><li>Meta-programming </li></ul>
  11. 11. Scripting <ul><li>Evaluate custom Groovy code </li></ul><ul><ul><ul><li>At run-time!!! </li></ul></ul></ul>
  12. 12. Builders <ul><li>Construct hierarchies </li></ul>
  13. 13. Builders - GAnt
  14. 14. Builders – Spring config
  15. 15. Categories
  16. 16. DSL <ul><li>Limited purpose language </li></ul><ul><li>Targeted to a particular domain </li></ul><ul><li>Friendlier API to a framework </li></ul><ul><ul><li>External </li></ul></ul><ul><ul><ul><li>SQL, HTML, CSS, … </li></ul></ul></ul><ul><ul><li>Internal </li></ul></ul>
  17. 17. DSL – Date manipulation
  18. 18. DSL – Hibernate criteria
  19. 19. DSL – Account manipulation
  20. 20. Dynamic method invocation GroovyObject invokeMethod() getProperty() setProperty() methodMissing() propertyMissing() MetaClass invokeMethod() properties methods
  21. 21. Summary <ul><li>Groovy </li></ul><ul><ul><li>Powerful Java extension </li></ul></ul><ul><ul><li>Tests, Builders, Scripting, DSLs </li></ul></ul><ul><ul><li>Contact me: vaclav@jetbrains.com </li></ul></ul>
  22. 22. Questions ?

×