1 / 43

An agile dynamic language for the Java Platform

An agile dynamic language for the Java Platform. Overview. JSR-241, aims to provide scripting language for Java developers Community driven, open source Compiles to Java byte code, runs inside of the JVM Written in Java and Groovy. Closures.

chiara
Download Presentation

An agile dynamic language for the Java Platform

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An agile dynamic language for the Java Platform

  2. Overview • JSR-241, aims to provide scripting language for Java developers • Community driven, open source • Compiles to Java byte code, runs inside of the JVM • Written in Java and Groovy

  3. Closures • Allows one piece of code to execute another piece of code that has been defined elsewhere • Can be done in Java with the Method-Object Pattern • Much cleaner in Groovy

  4. Example: Map Reduction (Java)

  5. Example: Map Reduction (Groovy)

  6. Ranges

  7. Ranges are Objects

  8. Expressive for Loop

  9. Groovy’s Type System • Everything is an object, there are no primitive types • Allows the programmer to choose between static and dynamic types • Type safe

  10. Example: Dynamic Typing

  11. Duck Typing • Objects can be polymorphic without being related by a common base class or interface

  12. Operator Overriding • Known to C++ programmers as operator overloading • Java provides no support for this • Can be done in Groovy, implemented based on the Value Object Pattern

  13. Overriding the == and + Operators

  14. Anonymous Inner Classes • Familiar to experienced Java developers • No support for anonymous inner classes • There exists a way to do this in Groovy with Maps

  15. Pattern for Groovy Anonymous Classes

  16. Anonymous Thread (Java)

  17. Anonymous Thread (Groovy)

  18. Multi-Threading • Disappointing, not much of an improvement above Java • Ability to use closures as opposed to implementing the Runnable interface or extending the Thread class and implementing the run() method • There is a problems with synchronized blocks in closures

  19. Master-Slave Example • For the Master Process a single instance of a closure definition can be used • For the Slave Processes a method that returns a new Closure object is used so that the closure can use variables bound at the time it is instantiated and not the time it is first used

  20. Master-Slave Example (Master)

  21. Master-Slave Example (Slaves)

  22. Master-Slave: Thread Spawning

  23. Design Patterns in Groovy • Many patterns are easier to use, program, and read than their Java counterparts • We can thank Closures and Dynamic Typing for this

  24. Design Patterns from the Groovy Website

  25. Iterator Pattern

  26. Visitor Pattern (Java)

  27. Visitor Pattern (Java)

  28. Visitor Pattern (Groovy) Using Closures

  29. Builder Pattern • Separates the construction of a complex object from its representation • Hides the internal representation of the product from the client

  30. XML Builder

  31. XML Builder

  32. Swing Builder

  33. XML-RPC

  34. Web Services

  35. JDBC

  36. JDBC Exception Handling

  37. GSQL

  38. Groovlets

  39. GSP

  40. GPath • Path expression language integrated into Groovy

  41. Simple Currying

  42. Currying Example

  43. References • http://www.manning.com/koenig/ • http://www.jroller.com/aalmiray/entry/anonymous_classes_in_groovy • http://groovy.codehaus.org/ • http://c2.com/cgi/wiki?ValueObject • https://gsp.dev.java.net/ • https://groovlet-examples.dev.java.net/

More Related