Bitter Java?
Sweeten with JRuby

   Brian Sam-Bodden
Java Today
Java is a 10+ year old programming language

          Java is the new COBOL

               Java is Dead

              L...
Java is not going anywhere

Because Java is everywhere!

   But Java is not perfect

and it is adjusting to keep up
Java has its jewels

JDBC, JMS, Servlets

and its blemishes...

   EJB < 3, JSF
But we have a secret weapon...

              On this corner...
  presenting the amazing, highly tuned, multi-
platform co...
The are more than 200+ languages implementations
                  for the Java VM


The Java VM is like that neighborhood...
Groovy, JRuby and all the new kids on the block are
just new additions to our beloved Swiss army knife
What’s Missing?
Java is solid on the server-side

            Java powers the enterprise

  Web development with Java has not been all tha...
Why Ruby?
Why not?
✓Object-Oriented
     ✓Elegant                        ✓General Purpose


✓ Multi-paradigm
                   Ruby         ...
Created by Yukihiro “Matz” Matsumoto

Developed in 1993, released in 1995

       Blended parts of his favorite languages:...
Ruby Ideals:

           Programming should be fun!

            Principle of Least Surprise

“I believe people want to ex...
JRuby
A non-Java language for the Java platform

   A Ruby interpreter written in Java

         Started life in 2001

   Curren...
Oh, come on! Grow up!
Ruby libraries from Java (like ActiveRecord)


➡Using Bean Scripting Framework (JDK <= 1.5)

   ➡Using JSR 223 Scripting A...
RubyGems comes pre-installed

               Mongrel supports JRuby

                    Rails just works

No native exten...
JRuby does not produce bytecode artifacts for
            the Ruby code (yet!)

     This is key difference with Groovy*

...
All you need to run JRuby is the Java JDK (=>1.4)
Familiar?




pure Ruby with Java players
Let’s try some interactive JRuby

   Fire up the JRuby console using Java Web Start

http://www.tc.umn.edu/%7Eenebo/websta...
IRB is the best to get acquainted with Ruby
A Simple
Comparison
Let’s do some file I/O...

First we need a text file
package com.integrallis;
import java.io.BufferedReader;             Let’s open the text file
import java.io.FileReader;
imp...
Let’s do it the Ruby way!
But wait! This just in...
    ... Ruby encapsulates common behaviors




➡   A one-liner version, yet is readable!
Why?
For Web applications...

                Best of both worlds:

    ➡Dynamic-Framework on the Front End (Rails)
➡Solid Back...
Got API-itis?

      Ruby’s ability to create concise DSLs

paired with Java’s richness of APIs and frameworks

   Java AP...
Got API-itis? JRuby+SWT
There are JRuby DSLs all ready to use...
                       Today!

         ActiveRecord-JDBC - OR-Wrapping

  Raven ...
JRuby on Rails
Java & JEE

     the most prevalent language

the most complete enterprise platform

 a rich ecosystem of web frameworks

...
Java & JEE

   plagued by mediocre web frameworks

    not well suited for rapid prototyping

in need of a dynamic languag...
Who could help Java on the Web Tier?
Ruby on Rails

a revolutionary web framework

   complete MVC solution

       fast prototyping

     killer AJAX support
Ruby on Rails

         a DSL for the web

leading the pack on the web 2.0 front

born from a product, not a committee

  ...
JRuby on Rails

the agility of rails - the scalability of Java

 JRuby likely to surpass Ruby in speed

sneak Ruby and RoR...
JRuby on Rails
JRuby on Rails
JRuby on Rails

       JEE servers are good at scaling up

      no more multi-process management

         use JRuby “mul...
JRuby on Rails
 deploy your Rails app as a WAR

leverage JDBC from ActiveRecord
JRuby &
Rapid Spring
Prototyping
JRuby+Spring RAD

      a simple example by the folks at jobster

          use JRuby for rapid prototyping

Spring contro...
JRuby+Spring RAD




   Simple JRuby controller
JRuby+Spring RAD




JSP view provides input to the Ruby controller
JRuby+Spring RAD




JSP view provides input to the Ruby controller
JRuby+Spring RAD

   this experimental library supports:

✓access to Spring beans from JRuby code
    ✓ access to Hibernat...
JRuby on
Springy Rails
JRoR on Spring
         Chris Nelson’s work


            ✓use rails-integration plugin
✓ expose WebApplicationContext in ...
JRoR on Spring
✓install goldspike rails-integration plugin on you JRoR app


 ✓ rake war:standalone:create to package a WA...
JRoR on Spring
rake war:standalone:create in action:
JRoR on Spring
generated WARs work on many servers:


    ✓Tomcat        ✓Glassfish
     ✓Jetty          ✓JBoss
JRoR on Spring
✓   add Chris’ Spring module:
JRoR on Spring

✓ Expand the generated   WAR

✓Add Spring application
   ➡ Application Code
   ➡ Libraries (Jars)
   ➡ Con...
JRoR on Spring
✓   access your Spring beans from a RoR controller
JRoR on Spring

   ✓add a new face to your Spring applications
 ✓   leverage thousands of open source projects

✓leverage ...
Resources
                               JRuby
                            www.jruby.org
                  rubyforge.org/p...
www.integrallis.com
Bitter Java, Sweeten with JRuby
Upcoming SlideShare
Loading in...5
×

Bitter Java, Sweeten with JRuby

7,092

Published on

Ways to make Java applications better and less complex with JRuby

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,092
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
152
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Bitter Java, Sweeten with JRuby

  1. 1. Bitter Java? Sweeten with JRuby Brian Sam-Bodden
  2. 2. Java Today
  3. 3. Java is a 10+ year old programming language Java is the new COBOL Java is Dead Long live Java!
  4. 4. Java is not going anywhere Because Java is everywhere! But Java is not perfect and it is adjusting to keep up
  5. 5. Java has its jewels JDBC, JMS, Servlets and its blemishes... EJB < 3, JSF
  6. 6. But we have a secret weapon... On this corner... presenting the amazing, highly tuned, multi- platform computing engine that dominates the present and permeates the future The JVM
  7. 7. The are more than 200+ languages implementations for the Java VM The Java VM is like that neighborhood with low taxes and good schools... everyone wants in Regardless of where we go with Java “the language”, Java “the platform” is here to stay
  8. 8. Groovy, JRuby and all the new kids on the block are just new additions to our beloved Swiss army knife
  9. 9. What’s Missing?
  10. 10. Java is solid on the server-side Java powers the enterprise Web development with Java has not been all that successful in the presentation tier Dynamic languages and frameworks based on dynamic languages have proved to be better suited for this
  11. 11. Why Ruby?
  12. 12. Why not?
  13. 13. ✓Object-Oriented ✓Elegant ✓General Purpose ✓ Multi-paradigm Ruby ✓ Interpreted is... ✓Reflective ✓Dynamic ✓ Garbage-collected
  14. 14. Created by Yukihiro “Matz” Matsumoto Developed in 1993, released in 1995 Blended parts of his favorite languages: Perl, Smalltalk, Sather, Eiffel, CLU, Ada and Lisp More popular than Python in Japan
  15. 15. Ruby Ideals: Programming should be fun! Principle of Least Surprise “I believe people want to express themselves when they program. They don’t want to fight with the language. Programming languages must feel natural to programmers.” Matz
  16. 16. JRuby
  17. 17. A non-Java language for the Java platform A Ruby interpreter written in Java Started life in 2001 Current version is 1.0 (1.1b1) Open Source
  18. 18. Oh, come on! Grow up!
  19. 19. Ruby libraries from Java (like ActiveRecord) ➡Using Bean Scripting Framework (JDK <= 1.5) ➡Using JSR 223 Scripting API (JDK > 1.5) Java libraries from Ruby (Swing, SWT)
  20. 20. RubyGems comes pre-installed Mongrel supports JRuby Rails just works No native extensions (unless by native you mean Java ;-)
  21. 21. JRuby does not produce bytecode artifacts for the Ruby code (yet!) This is key difference with Groovy* Corporate backing :-) Sun and Thoughtworks have folks working on JRuby full-time
  22. 22. All you need to run JRuby is the Java JDK (=>1.4)
  23. 23. Familiar? pure Ruby with Java players
  24. 24. Let’s try some interactive JRuby Fire up the JRuby console using Java Web Start http://www.tc.umn.edu/%7Eenebo/webstart/jirb-console/console.jnlp Java version of IRB (Interactive RuBy) tool
  25. 25. IRB is the best to get acquainted with Ruby
  26. 26. A Simple Comparison
  27. 27. Let’s do some file I/O... First we need a text file
  28. 28. package com.integrallis; import java.io.BufferedReader; Let’s open the text file import java.io.FileReader; import java.io.IOException; and print out its contents public class MyFileReader { ...in Java public static void main(String[] args) { try { BufferedReader in = new BufferedReader(new FileReader(quot;read_me.txtquot;)); String str; while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); } catch (IOException e) { e.printStackTrace(); } } }
  29. 29. Let’s do it the Ruby way!
  30. 30. But wait! This just in... ... Ruby encapsulates common behaviors ➡ A one-liner version, yet is readable!
  31. 31. Why?
  32. 32. For Web applications... Best of both worlds: ➡Dynamic-Framework on the Front End (Rails) ➡Solid Back End battle tested technologies (Spring/EJB3)
  33. 33. Got API-itis? Ruby’s ability to create concise DSLs paired with Java’s richness of APIs and frameworks Java APIs are robust, fully-featured, flexible... ...which makes them complex A JRuby DSL can help us in the 80-20 scenarios
  34. 34. Got API-itis? JRuby+SWT
  35. 35. There are JRuby DSLs all ready to use... Today! ActiveRecord-JDBC - OR-Wrapping Raven - Wrapper for Rake, RubyGems and Maven AntBuilder - Wrapper for Ant JRake - Wrapper for Rake JtestR - Test Java code with the best Ruby testing tools
  36. 36. JRuby on Rails
  37. 37. Java & JEE the most prevalent language the most complete enterprise platform a rich ecosystem of web frameworks a vibrant open source community
  38. 38. Java & JEE plagued by mediocre web frameworks not well suited for rapid prototyping in need of a dynamic language web framework one level of abstraction too low for the web
  39. 39. Who could help Java on the Web Tier?
  40. 40. Ruby on Rails a revolutionary web framework complete MVC solution fast prototyping killer AJAX support
  41. 41. Ruby on Rails a DSL for the web leading the pack on the web 2.0 front born from a product, not a committee a vibrant open source community
  42. 42. JRuby on Rails the agility of rails - the scalability of Java JRuby likely to surpass Ruby in speed sneak Ruby and RoR into the enterprise!
  43. 43. JRuby on Rails
  44. 44. JRuby on Rails
  45. 45. JRuby on Rails JEE servers are good at scaling up no more multi-process management use JRuby “multi-VM” support leverage the maturity of the JVM and JEE servers
  46. 46. JRuby on Rails deploy your Rails app as a WAR leverage JDBC from ActiveRecord
  47. 47. JRuby & Rapid Spring Prototyping
  48. 48. JRuby+Spring RAD a simple example by the folks at jobster use JRuby for rapid prototyping Spring controller that delegates to a JRuby controller JRuby controllers live alongside your JSPs
  49. 49. JRuby+Spring RAD Simple JRuby controller
  50. 50. JRuby+Spring RAD JSP view provides input to the Ruby controller
  51. 51. JRuby+Spring RAD JSP view provides input to the Ruby controller
  52. 52. JRuby+Spring RAD this experimental library supports: ✓access to Spring beans from JRuby code ✓ access to Hibernate queries
  53. 53. JRuby on Springy Rails
  54. 54. JRoR on Spring Chris Nelson’s work ✓use rails-integration plugin ✓ expose WebApplicationContext in a RoR controller ✓include Spring - Spring plugin for JRuby
  55. 55. JRoR on Spring ✓install goldspike rails-integration plugin on you JRoR app ✓ rake war:standalone:create to package a WAR with: ➡Your RoR app ➡JRuby and Rails libraries
  56. 56. JRoR on Spring rake war:standalone:create in action:
  57. 57. JRoR on Spring generated WARs work on many servers: ✓Tomcat ✓Glassfish ✓Jetty ✓JBoss
  58. 58. JRoR on Spring ✓ add Chris’ Spring module:
  59. 59. JRoR on Spring ✓ Expand the generated WAR ✓Add Spring application ➡ Application Code ➡ Libraries (Jars) ➡ Config Files
  60. 60. JRoR on Spring ✓ access your Spring beans from a RoR controller
  61. 61. JRoR on Spring ✓add a new face to your Spring applications ✓ leverage thousands of open source projects ✓leverage the good parts of JEE like JDBC and JMS
  62. 62. Resources JRuby www.jruby.org rubyforge.org/projects/jruby-extras JRuby Rails Integration www.headius.com/jrubywiki/index.php/Rails_Integration headius.blogspot.com/2006/11/advanced-rails-deployment-with-jruby.html RAD Spring Prototyping with JRuby thebogles.com/blog/projects/ruby-on-spring/ www.botspiritcompany.com/src/springruby/example_ruby_spring.html Chris Nelson’s Work mysterycoder.blogspot.com/2007/06/spring-jruby.html mysterycoder.blogspot.com/2007/06/include-spring.html
  63. 63. www.integrallis.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×