Singing Java with JRuby         Sinatra     A melodious song        on JRuby                   K.Gautam                  @...
Ruby the languageCreated byYukihiroMatsumoto
JRuby        Developers:        Ola Bini,        Nick Sieger,        Charles Nutter,        Thomas        Enebo.
SinatraBlake Mizeranyand Many otherConrtibuters
So Lets look at Ruby
Hard Facts onDynamic
Hard Facts onInterpreted
Hard Facts onReflective
Hard Facts onObjectOriented
Implemented in C  Hard Facts on
So what is JRuby ?           +                   =Isnt that obvious from the name ?So JRuby is just another Ruby interpret...
Why JRuby?
Why JRuby?True Multi-threading
Why JRuby?A well tuned Virtual Machine
Why JRuby?Simple and Easy Language
Why JRuby?Ruby was designed to make programmersHappy
Why JRuby?Fewer Bugs with Ruby
So Lets compare Java and Ruby ....And Why its better to combine them
Java vs Ruby                              Getters and Setters       1 class Foo{        2 private int bar1 , bar2;        ...
Java vs Ruby                              Working with Lists       1   List<String> friends = new LinkedList<String>();   ...
Everything is an object (Literally !!)1   3.times { puts "Microsoft is Evil" }2   Microsoft is Evil3   Microsoft is Evil4 ...
Meta Programmingjruby-1.6.5 :002 > eval("puts I can Program Myself")I can Program Myself => nil
If Ruby is so good then why Java ?
If ruby is so good then why Java ?● Java wins hands down in the Performance department
If ruby is so good then why Java ?● True Multi-Threading
Getting JRubyMethod 1:● Install MRI and RVM from  ○ Package manager (Linux only)  ○ ruby-lang.org● Then do "rvm install jr...
Getting JRubyMethod 2 :● Get it Directly from jruby.org
Running JRuby Programs● jruby Foo.rb● java -jar jruby-complete.jar Foo.rb
AOT compilation of Jruby● jrubyc Foo.rb● java -jar jruby-complete.jar foo.class
Using java classes in Jruby1 include Java 2 java_import java.lang.Thread 3 java_import java.lang.System 4 class SomeClass ...
Now onto Sinatra● Sinatra is a DSL for quickly creating web-  apps with Ruby● http://sinatrarb.com● Best Installed as "gem...
Sinatra saying Hello1 require rubygems2 require sinatra3 require data_mapper4 set :bind , 0.0.0.05 get / do6 "Hello there ...
Thank You
JRuby and Sinatra
Upcoming SlideShare
Loading in...5
×

JRuby and Sinatra

3,619

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,619
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "JRuby and Sinatra"

  1. 1. Singing Java with JRuby Sinatra A melodious song on JRuby K.Gautam @gautamNitish
  2. 2. Ruby the languageCreated byYukihiroMatsumoto
  3. 3. JRuby Developers: Ola Bini, Nick Sieger, Charles Nutter, Thomas Enebo.
  4. 4. SinatraBlake Mizeranyand Many otherConrtibuters
  5. 5. So Lets look at Ruby
  6. 6. Hard Facts onDynamic
  7. 7. Hard Facts onInterpreted
  8. 8. Hard Facts onReflective
  9. 9. Hard Facts onObjectOriented
  10. 10. Implemented in C Hard Facts on
  11. 11. So what is JRuby ? + =Isnt that obvious from the name ?So JRuby is just another Ruby interpreter.
  12. 12. Why JRuby?
  13. 13. Why JRuby?True Multi-threading
  14. 14. Why JRuby?A well tuned Virtual Machine
  15. 15. Why JRuby?Simple and Easy Language
  16. 16. Why JRuby?Ruby was designed to make programmersHappy
  17. 17. Why JRuby?Fewer Bugs with Ruby
  18. 18. So Lets compare Java and Ruby ....And Why its better to combine them
  19. 19. Java vs Ruby The Minimum Program 1 class Foo{ 2 public static void main (String []args){Java 3 } 4}Ruby
  20. 20. Java vs Ruby Getters and Setters 1 class Foo{ 2 private int bar1 , bar2; 3 public int getBar1(){ return this.bar1; } 4 public int getBar2(){ return this.bar2; } 5 public void setBar2(int bar2){Java 6 this.bar2=bar2; 7 } 8 public void setBar1(int bar1){ 9 this.bar1=bar1; 10 } 11 } 1 class FooRuby 2 attr_accessor :bar1 , :bar2 3 end
  21. 21. Java vs Ruby Working with Lists 1 List<String> friends = new LinkedList<String>(); 2 List<String> enemies = new LinkedList<String>(); 3 friends.add("Java"); friends.add("JRuby"); 4 friends.add("Jython"); friends.add("Scala")Java 5 enemies.add("C#"); enemies.add("IronRuby"); 6 enemies.add("IronPython"); enemies.add("F#"); 1 friends=[] 2 enemies=[]Ruby 3 4 friends<< "Java" << "JRuby" << "Jython" << "Scala" enemies<< "c#" << "IronRuby" << "IronPython" << "F#"
  22. 22. Everything is an object (Literally !!)1 3.times { puts "Microsoft is Evil" }2 Microsoft is Evil3 Microsoft is Evil4 Microsoft is Evil5 => 3jruby-1.6.5 :011 > "Something".class => Stringjruby-1.6.5 :012 > 22.class => Fixnum
  23. 23. Meta Programmingjruby-1.6.5 :002 > eval("puts I can Program Myself")I can Program Myself => nil
  24. 24. If Ruby is so good then why Java ?
  25. 25. If ruby is so good then why Java ?● Java wins hands down in the Performance department
  26. 26. If ruby is so good then why Java ?● True Multi-Threading
  27. 27. Getting JRubyMethod 1:● Install MRI and RVM from ○ Package manager (Linux only) ○ ruby-lang.org● Then do "rvm install jruby"
  28. 28. Getting JRubyMethod 2 :● Get it Directly from jruby.org
  29. 29. Running JRuby Programs● jruby Foo.rb● java -jar jruby-complete.jar Foo.rb
  30. 30. AOT compilation of Jruby● jrubyc Foo.rb● java -jar jruby-complete.jar foo.class
  31. 31. Using java classes in Jruby1 include Java 2 java_import java.lang.Thread 3 java_import java.lang.System 4 class SomeClass 5 include java.lang.Runnable 6 def run 7 5.times do 8 System.out.println "Executing Thread : #{Thread.current_thread.get_id}" 9 end10 end11 end12 5.times{13 Thread.new(SomeClass.new).start14 }
  32. 32. Now onto Sinatra● Sinatra is a DSL for quickly creating web- apps with Ruby● http://sinatrarb.com● Best Installed as "gem install sinatra"
  33. 33. Sinatra saying Hello1 require rubygems2 require sinatra3 require data_mapper4 set :bind , 0.0.0.05 get / do6 "Hello there this is Frank Sinatra from beyondthe grave"7 end
  34. 34. Thank You

×