JRuby - The Best of Java and Ruby


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

JRuby - The Best of Java and Ruby

  1. 1. JRuby The Best of Java and Ruby by Evgeny RahmanImage source: https://github.com/jruby/collateral/ by Tony Price (tonyxprice)JRuby is Copyright (c) 2007-2012 The JRuby project
  2. 2. A little bit about Ruby• Created in 1993 by Yukihiro Matsumoto (“Matz”).• An object-oriented scripting language.• Guiding philosophy - a language that feels natural to programmers.• Principle of least surprise.
  3. 3. Adoption• First English mailing list appeared in 1999.• “Programming Ruby” (aka “The Pickaxe Book”) by Dave Thomas and Andy Hunt released in 2000.• Interest grew considerably in 2005 because of the Rails framework.• 225,000 Ruby projects on GitHub.
  4. 4. Examples• The all-important Hello World: puts "Hello World"• Array iteration: [a, b, c, d, e].each { |x| puts x }• Hash operations: animal_sounds = { :dog => woof, :cat => meow} animal_sounds[:dog] #=> woof
  5. 5. Examples• unless: "Unicorns exist!" unless unicorns.empty?• Blocks: flights = flights.sort do |flight_a, flight_b| flight_a.price <=> flight_b.price end• Loops: 100.times { |i| puts "The number is #{i}" }
  6. 6. JRuby• Created by Jan Arne Petersen in 2001.• Ruby implementation that runs on the JVM.• Current core team of nine developers.• Currently 1.7.0 is out in preview.• Supports MRI 1.8.7 and 1.9.3.• Code is JIT and AOT compiled into JVM bytecode.
  7. 7. Advantages• Java interop – use the Java ecosystem and your existing libraries.• Threading – real, JVM multithreading.• InvokeDynamic in Java 7 – optimization in performance for JRuby.• Deployment – several options, including familiar, Java ones.
  8. 8. Java interop – simple!require javajava_import java.lang.Mathputs java.lang.Math::PI #=> 3.14159265358979
  9. 9. Java interop – libraries require java‘ require path/to/yourlib.jar Now if you do: java_import "org.your.lib.YourClass" Your class is available as Java-style: org.your.lib.YourClass Ruby-style: Java::YourLib::YourClass and directly referenced as YourClassMore information: https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
  10. 10. Caveats• Gems with C extensions – use alternatives.• JVM startup time – TDD, scripting.• No compilation – more testing, more discipline.• Development-Deployment gap.
  11. 11. Deployment• This was the missing link for Ruby in the enterprise *• Warbler – create a WAR and deploy it to a Java EE container.• jet.pack – package your JRuby rack app for Jetty.• Trinidad – run Rails or Rack applications on embedded Tomcat container.• Mizuno – jetty-powered server for JRuby in the style of Thin or WEBRick• Torquebox – JBoss AS-based Ruby application platform • Rack (Rails, Sinatra), JDBC, Daemons, Scheduled Jobs, Messaging, Asynchronous Tasks• “Deploying with JRuby” – Joe Kutner, The Pragmatic Bookshelf.* My humble opinion
  12. 12. Community• Really nice people!• Core team is great, but there are also many other contributors.• Blogs, Twitter, IRC, Mailing Lists, Wiki, Issue tracker.• JRubyConf organized every year since 2009 – this year’s was in Minneapolis, MN.• Best place to start: jruby.org
  13. 13. Resources• http://jruby.org/• http://github.com/jruby/ - GitHub• http://jira.codehaus.org/browse/JRUBY - issue tracker• http://kenai.com/projects/jruby/pages/Home - old wiki• https://github.com/jruby/jruby/wiki/ - new wiki• #jruby IRC channel on FreeNode IRC• @jruby on Twitter