Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JRuby - The Best of Java and Ruby

JRuby - The Best of Java and Ruby

JRuby is an implementation of the Ruby programming language on the JVM. It represents the exciting combination of the dynamism, expressiveness, and simplicity of Ruby with the depth, maturity, and power of the Java ecosystem. Most significantly, JRuby gives you the ability to try the Ruby programming language while preserving your investment in Java and JVM technologies.

This talk will go over some of the reasons to write code in JRuby, how to leverage existing Java libraries with JRuby, and some real-world advice on using it in production systems.

Evgeny Rahman

October 11, 2012
Tweet

More Decks by Evgeny Rahman

Other Decks in Programming

Transcript

  1. JRuby The Best of Java and Ruby by Evgeny Rahman

    Image source: https://github.com/jruby/collateral/ by Tony Price (tonyxprice) JRuby is Copyright (c) 2007-2012 The JRuby project
  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. 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. 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. 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. 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. 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. 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 YourClass More information: https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
  9. Caveats • Gems with C extensions – use alternatives. •

    JVM startup time – TDD, scripting. • No compilation – more testing, more discipline. • Development-Deployment gap.
  10. 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
  11. 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
  12. 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