Dynamic Languages on the JVM
-
Upload
elliando-dias -
Category
Technology
-
view
1.346 -
download
5
Transcript of Dynamic Languages on the JVM
Dynamic Languages on the JVM
Groovy, Grails, JRuby, and JRuby on Rails
Matt StineMemphis/Mid-South JUG
October 18, 2007
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
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
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
Metaprogramming (Groovy)
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
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
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
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.
What does all of this have to do with Java?!?!?!
Both of these languages are
FIRST CLASS CITIZENS on the Java Virtual
Machine!
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
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, …)
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
Why JRuby?
JRuby over Java technologyLanguage features
Blocks, modules, metaprogramming, dynamic-typing
Ruby applications/librariesRails, Rspec, Rake, Raven, other
R’s
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
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
JRuby on Rails: Deployment
Use goldspike plugin to build WAR file
Deploy to any Java EE App Server
DEMO
JUG Meeting AppCreate MeetingsCreate AttendeesAssociate Attendees w/
MeetingsConduct Prize Drawings
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!)
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
Based on solid foundationsGroovySpring and Spring MVCHibernateQuartzSitemeshEmbedded Jetty and HSQLDB
And, of course, Java™ technology
Grails
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).
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
DEMO
JUG Meeting AppCreate MeetingsCreate AttendeesAssociate Attendees w/
MeetingsConduct Prize Drawings
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
Q/A
Questions???
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