dynamic languages on the jvm
TRANSCRIPT
![Page 1: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/1.jpg)
Dynamic Languages on the JVM
Groovy, Grails, JRuby, and JRuby on Rails
Matt StineMemphis/Mid-South JUG
October 18, 2007
![Page 2: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/2.jpg)
Dynamic Languages "Dynamic programming language is a term
used broadly in computer science to describe a class of high level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, or by extending objects and definitions, or by modifying the type system, all during program execution. These behaviors can be emulated in nearly any language of sufficient complexity, but dynamic languages provide direct tools to make use of them." - Wikipedia
![Page 3: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/3.jpg)
Examples of Dynamic Languages: Ruby
Created by Yukihiro “matz” Matsumoto First released in 1995 Currently at version 1.8.6 http://www.ruby-lang.org
Groovy Project founded by James Strachan and Bob
McWhirter in 2003 Became JSR-241 in 2004 Currently at version 1.1-RC-1 http://groovy.codehaus.org
![Page 4: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/4.jpg)
DL Quick Feature Tour Absolutely everything is an object – no
primitives! 7.class => java.lang.Integer
Lots of syntactical sugar for lists, maps, ranges, regular expressions, etc.
def numbers = [1,2,3] // a list def ages = 18..65 // a range def currencies = [USD: “US Dollar”, GBP: “Pounds”, EUR: “Euros”]
Dynamic typing Blocks / Closures
3.times {println it} Metaprogramming
Dynamically generate classes Modify existing classes Special dispatching to pretend things exist
![Page 5: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/5.jpg)
Metaprogramming (Groovy)
![Page 6: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/6.jpg)
DL for the Web
Ruby = Ruby on RailsFull-stack MVC web development
frameworkOpen Source (MIT)First released in 2004 by David
Heinemeier HanssonCurrently at version 1.2.4
(2.0 coming soon!!!)Ruby and Rails books are outselling
Perl bookshttp://rubyonrails.org
![Page 7: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/7.jpg)
DL for the WebGroovy = Grails
(formerly “Groovy on Rails”)
Model View Controller (MVC) action-based web framework
Open Source (Apache 2.0)First released in early 2006 by Graeme
Rocher, Guillaume LaForge, and Steven Devijver
Currently at version 0.6(1.0 coming soon!!!)
Now backed by a company, G2one, formed by authors (October 2007).
http://grails.org
![Page 8: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/8.jpg)
DL Web Framework SimilaritiesConvention over configuration
Why punish the common cases?Encourages standard practicesEverything simpler and smaller
Don’t Repeat Yourself (DRY)Frameworks written around
minimizing repetitionRepetitive code harmful to
adaptability
![Page 9: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/9.jpg)
DL Web Framework SimilaritiesAgile development environment
No recompile, deploy, restart cyclesSimple tools to generate code quicklyTesting built into the frameworks
Full StackAll technologies necessary to build
persistence, service, and web layers fully integrated.
![Page 10: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/10.jpg)
What does all of this have to do with Java?!?!?!
Both of these languages are
FIRST CLASS CITIZENS on the Java Virtual
Machine!
![Page 11: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/11.jpg)
JRuby
Started in 2002 Java platform implementation of
Ruby languageOpen source, many active
contributors, including full-time Sun employees
Currently at version 1.0.1Fully compatible with Ruby 1.8.5
(including Rails!)http://jruby.codehaus.org
![Page 12: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/12.jpg)
JRuby
Integrates with Java technologyCall to Ruby from Java technology via
JSR 223, BSF, SpringUse Java class files from Ruby (e.g.
Script Java)Growing set of external projects
based on JRubyJRuby-extras (GoldSpike,
ActiveRecord-JDBC, Mongrel-JRuby, Mongrel-JCluster, …)
![Page 13: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/13.jpg)
Why JRuby?
JRuby over RubyStrong likelihood it will be faster soonBetter scalability with native
threadingNative Unicode supportCompilationIntegration with Java librariesEasier path to getting Ruby in the
enterprise
![Page 14: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/14.jpg)
Why JRuby?
JRuby over Java technologyLanguage features
Blocks, modules, metaprogramming, dynamic-typing
Ruby applications/librariesRails, Rspec, Rake, Raven, other
R’s
![Page 15: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/15.jpg)
Why JRuby on Rails? “Less Rails code that Java application
configuration.” Growing excited community of developers Makes small apps trivial to create Deployment to Java application servers Java technology production environments are
pervasive Easier to switch framework vs. whole architecture Lower barrier to entry
Broader, more scalable database support Integration w/ Java technology libs, legacy
services
![Page 16: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/16.jpg)
JRuby on Rails: Java EE PlatformPool database connectionsAccess any JNDI resourceAccess any Java EE platform TLA:
Java Persistence API (JPA)Java Management Extensions (JMX)Enterprise JavaBeans™ (EJB™)Java Message Service (JMS) APISOAP/WSDL/SOA
![Page 17: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/17.jpg)
JRuby on Rails: Deployment
Use goldspike plugin to build WAR file
Deploy to any Java EE App Server
![Page 18: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/18.jpg)
DEMO
JUG Meeting AppCreate MeetingsCreate AttendeesAssociate Attendees w/
MeetingsConduct Prize Drawings
![Page 19: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/19.jpg)
Groovy
Written specifically for the JVM (JSR-241)
Generates bytecode for the JVM and supports both static and dynamic typing
A runtime and library (GDK) extension to Java
Expressive Java-like syntaxSame object model as Java (a
Groovy object is a Java object!)
![Page 20: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/20.jpg)
Groovy
Same mechanisms for:Class extension and interface
implementationMethod overloadingJavaBean™ creation (with a twist!)
But brings the dynamic features of Ruby, Python, and Smalltalk to a Java friendly environment
![Page 21: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/21.jpg)
Based on solid foundationsGroovySpring and Spring MVCHibernateQuartzSitemeshEmbedded Jetty and HSQLDB
And, of course, Java™ technology
Grails
![Page 22: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/22.jpg)
Why Groovy/Grails?
Simplicity and flexibility All the power of the underlying frameworks
is available to you, but you don’t have to use it!
Mindshare integration Developers have no need to abandon their
existing Java knowledge
API integration Groovy/Grails provides elegant extensions to
existing good APIs (GORM).
![Page 23: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/23.jpg)
Why Groovy/Grails?
Blended Development Approach Write appropriate portions of your
application in Groovy and/or Java
Dynamic Language Features Pure OO Syntax Sugar Dynamic typing Closures Metaprogramming
![Page 24: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/24.jpg)
DEMO
JUG Meeting AppCreate MeetingsCreate AttendeesAssociate Attendees w/
MeetingsConduct Prize Drawings
![Page 25: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/25.jpg)
Dynamic Languages SummaryJVM integration means zero loss of
Java investment (developer knowledge, infrastructure)
Powerful language features increase developer productivity
Frameworks designed for rapid, agile development of web applications
![Page 26: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/26.jpg)
Q/A
Questions???
![Page 27: Dynamic Languages on the JVM](https://reader035.vdocument.in/reader035/viewer/2022062307/555684aad8b42a182f8b48e7/html5/thumbnails/27.jpg)
Resources
http://ruby-lang.org http://jruby.codehaus.org http://rubyonrails.org http://groovy.codehaus.org http://grails.codehaus.org http://memphisjug-dynamiclanguages-o
ct07.googlecode.com