SlideShare a Scribd company logo
Java, Ruby & Rails
The Java platform “ It’s all about the Java Virtual Machine. That’s the integration hub.” Gosling, Sun Tech Days 2007 Lots of new languages for the JVM Scala, Clojure, Groovy, Jython, (J)Ruby, JavaScript (Rhino), JavaFX The DaVinci Machine JSR-292 Target JDK 7 invokedynamic instruction
Why Ruby? Ubiquity C-Ruby (MRI) JRuby IronRuby (.NET) Rubinius, Maglev, YARV Scripting java shebang/backticks Rails Framework Support from Sun, Thoughtworks Most likely to succeed?
What is Ruby? Created by Yukihiro Matsumoto (Matz) in 1993 “ A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.”  The principle of least surprise Runtime efficiency not a top priority “ More powerful than Perl, more OO  than Python” MRI is the specification RubySpec is in the works
Ruby Characteristics Interpreted Object oriented ” myString”.upcase 2_500.+2 44.modulo 5 Reflective Garbage collected Duck typing If it walks like a duck and quacks like a duck it must be a duck
Dynamic features Reopen existing classes redefine methods “ monkeypatching” Meta-programming Method aliasing alias_method  :validates_size_of ,  :validates_length_of method_missing Eg provide a generic sort method sort_by_x Closures
Core Ruby tools (j)ruby the interpreter (j)irb interactive ruby, ~readline support, tab completion ri ruby interactive ~man pages rdoc html doc ~javadoc rake ant/make for ruby gem package manager
Ruby anatomy Classes are CamelCased Methods are under_scored Generally no need for curly braces, parentheses, semicolon or return statement code more compact Comments =begin block comment =end # line comment Variables Constant @@classVariable @instanceVariable localVariable :symbol
Example
Ruby structure Modules Module::Class Mix-ins interfaces with functionality Namespace Subclass < Superclass Single inheritance only Files are named *.rb can hold many classes require ’file’ include Module searches $LOAD_PATH
Access modifiers private Private to this instance (might be a subclass) You can’t specify the receiver, not even self protected Can be called by instances of the same class Eg use for comparators  public FFA private :method or private (until end) The modifiers are methods, not keywords
Testing Test::Unit::TestCase xUnit for ruby JRuby to test Java code? JtestR to invoke Code coverage  might be an issue RSpec BDD
Method signature - Java Method overloading Number of method signatures increases fast if flexibility is wanted
Method signature – PL/SQL Named parameters Still have to change method signature too add parameters
Method signature – Ruby Hash as optional parameter, not named parameters No need to change method signature Hash doesn’t need curly braces Method overload unavailable *args => arguments array
More syntax examples =~  regexp matcher myString =~ /[0-9]+/ %w[]  String array myArray = %w[ruby java haskell] {||}   or  do || end  closures  (and embedded variables) myHash.each { |k, v| puts k+’ is ‘+v } myHash.each do |key, val| puts “#{key} is #{val}” end
Ruby on Rails MVC Framework “ Rails is the most well thought-out web development framework I’ve ever used. And that’s in a decade of doing web applications for a living. I’ve built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.” -James Duncan Davidson, Creator of Tomcat and Ant “ Rails is the killer app for Ruby.” Yukihiro Matsumoto, Creator of Ruby
RoR principles Opinionated software Convention over configuration DRY REST GET /products #get all GET /products/42 #get id=42 POST /products #create Fast feedback loop just reload, no compile Rails itself is a gem
Ruby on Rails concepts rails <appname> generates skeleton  routes.rb ~struts-config.xml *.html.erb ~JSP Generators Generates model, view, controller, tests Partials (html.erb snippets) Plugins (instead of gems) Default database is sqlite3 (via JDBC for JRuby) Filters (defined in controller)
RoR tools rails <appname> -d <database> script/generate scaffold Person name:string script/server script/console irb with access to the application script/dbconsole enter SQL script/server –debugger debugger in the code drops to console
ActiveRecord O/R mapping Db migrations, dev, test, prod   up and down database agnostic rake db:migrate config/database.yml Opinionated software primary key named id pluralization class Book => db books
RoR model example class BlogPost < ActiveRecord::Base belongs_to :author has_many :comments validates_presence_of :title end comments table needs blog_post_id blog_posts table needs author_id New post need title field
A/R Metaprogramming
A/R Metaprogramming
ActiveSupport::TestCase Inherits Test::Unit::TestCase Provides helpers, eg http calls <app>/test functional integration unit fixtures/fixtures.yml rake
Jruby Motivation The JVM Sneak into the enterprise Reuse infrastructure Integrate with Java applications Performance and scalability
JRuby on Rails Develop as Java Netbeans Eclipse Integrate with Java Call EJBs Use JMS queues Use JNDI  Use JAAS Deploy on Java As *.war using warbler Rails deployer (JBoss, Glassfish)
Java integration include Java / require ”java” include Java::JavaxSwing include_class &quot;javax.naming.InitialContext” require ”path/to/my.jar” prefix javaclasses to avoid name collisions String => JString include_class 'java.lang.String’  {|package,name| &quot;J#{name}&quot; }  Method alias System.currentTimeMillis => System.current_time_millis Getters and setters behaves like attr_accessor fields
IDE support Eclipse - DLTK (Dynamic Languages Toolkit) Eclipse foundation plugin Support for TCL, Python, Ruby  No Rails Eclipse - Aptana RadRails RDT Ruby Editor Rails support generators/scripts Visual debug Testrunner Netbeans Official plugin
Conclusion Ruby is sweet! Syntactic sugar Fun to work with Ruby is useful! Integrate with Java OO scripting Rails is probably fast enough Ruby is hard! “ Good programmers become better, bad programmers become worse” Test, test, test
Thank you and Namaste
Contact © Devoteam Consulting A/S. This document  is not  to be copied or reproduced in any way without the  express permission of Devoteam Consulting. AUSTRIA BELGIUM CZECH REPUBLIC DENMARK FRANCE MOROCCO NETHERLANDS NORWAY POLAND SAUDI ARABIA SPAIN SWEDEN SWITZERLAND  UNITED ARAB EMIRATES UNITED KINGDOM +46 (0)733-812135 Phone: [email_address] E-mail: Address Peter Sönnergren Person: CONTACT Author:  Date:  # ID:  DOCUMENT

More Related Content

PDF
Ruby - a tester's best friend
PPTX
Java 7 Whats New(), Whats Next() from Oredev
ODP
Open Source Compiler Construction for the JVM
PDF
Connecting the Worlds of Java and Ruby with JRuby
KEY
Jruby synergy-of-ruby-and-java
PPTX
JRuby in Java Projects
PDF
JRuby - Programmer's Best Friend on JVM
PDF
Using Java from Ruby with JRuby IRB
Ruby - a tester's best friend
Java 7 Whats New(), Whats Next() from Oredev
Open Source Compiler Construction for the JVM
Connecting the Worlds of Java and Ruby with JRuby
Jruby synergy-of-ruby-and-java
JRuby in Java Projects
JRuby - Programmer's Best Friend on JVM
Using Java from Ruby with JRuby IRB

What's hot (19)

PDF
Introduction to Ruby on Rails
PPT
PDF
Ruby for C#-ers (ScanDevConf 2010)
PDF
An Introduction to Java Compiler and Runtime
KEY
Grand Central Dispatch
PPTX
Java byte code & virtual machine
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
PDF
Java ScriptingJava Scripting: One VM, Many Languages
PPTX
Java introduction
PDF
Online game server on Akka.NET (NDC2016)
PDF
Security Goodness with Ruby on Rails
KEY
Ruby on Rails Training - Module 1
PDF
Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam
PDF
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
PPTX
PDF
JRuby Basics
PDF
Quick Intro To JRuby
PDF
DataMapper on Infinispan
PDF
Basics of java
Introduction to Ruby on Rails
Ruby for C#-ers (ScanDevConf 2010)
An Introduction to Java Compiler and Runtime
Grand Central Dispatch
Java byte code & virtual machine
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Java ScriptingJava Scripting: One VM, Many Languages
Java introduction
Online game server on Akka.NET (NDC2016)
Security Goodness with Ruby on Rails
Ruby on Rails Training - Module 1
Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
JRuby Basics
Quick Intro To JRuby
DataMapper on Infinispan
Basics of java
Ad

Similar to Java, Ruby & Rails (20)

PPT
Practical JRuby
PDF
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
PPTX
Ruby on Rails All Hands Meeting
PPTX
Resthub lyonjug
PPT
Ruby On Rails
ODP
Dynamic Languages Web Frameworks Indicthreads 2009
DOCX
Java 7 Dolphin manjula kollipara
PDF
Introduction to JRuby
PPT
Dynamic Languages on the JVM
PPT
Ruby on rails
PPT
Ruby on rails
PPT
Ruby on Rails
PDF
JRuby and Google App Engine
PPT
Rollin onj Rubyv3
PPT
Jet presentation
PDF
Java 8 Overview
PPTX
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
PDF
Ruby on Rails Presentation
PPTX
It pro dev_birbilis_20101127_en
PDF
Zepto and the rise of the JavaScript Micro-Frameworks
Practical JRuby
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Ruby on Rails All Hands Meeting
Resthub lyonjug
Ruby On Rails
Dynamic Languages Web Frameworks Indicthreads 2009
Java 7 Dolphin manjula kollipara
Introduction to JRuby
Dynamic Languages on the JVM
Ruby on rails
Ruby on rails
Ruby on Rails
JRuby and Google App Engine
Rollin onj Rubyv3
Jet presentation
Java 8 Overview
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Ruby on Rails Presentation
It pro dev_birbilis_20101127_en
Zepto and the rise of the JavaScript Micro-Frameworks
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
cuic standard and advanced reporting.pdf
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Building Integrated photovoltaic BIPV_UPV.pdf
Modernizing your data center with Dell and AMD
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
cuic standard and advanced reporting.pdf
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...

Java, Ruby & Rails

  • 1. Java, Ruby & Rails
  • 2. The Java platform “ It’s all about the Java Virtual Machine. That’s the integration hub.” Gosling, Sun Tech Days 2007 Lots of new languages for the JVM Scala, Clojure, Groovy, Jython, (J)Ruby, JavaScript (Rhino), JavaFX The DaVinci Machine JSR-292 Target JDK 7 invokedynamic instruction
  • 3. Why Ruby? Ubiquity C-Ruby (MRI) JRuby IronRuby (.NET) Rubinius, Maglev, YARV Scripting java shebang/backticks Rails Framework Support from Sun, Thoughtworks Most likely to succeed?
  • 4. What is Ruby? Created by Yukihiro Matsumoto (Matz) in 1993 “ A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.” The principle of least surprise Runtime efficiency not a top priority “ More powerful than Perl, more OO than Python” MRI is the specification RubySpec is in the works
  • 5. Ruby Characteristics Interpreted Object oriented ” myString”.upcase 2_500.+2 44.modulo 5 Reflective Garbage collected Duck typing If it walks like a duck and quacks like a duck it must be a duck
  • 6. Dynamic features Reopen existing classes redefine methods “ monkeypatching” Meta-programming Method aliasing alias_method :validates_size_of , :validates_length_of method_missing Eg provide a generic sort method sort_by_x Closures
  • 7. Core Ruby tools (j)ruby the interpreter (j)irb interactive ruby, ~readline support, tab completion ri ruby interactive ~man pages rdoc html doc ~javadoc rake ant/make for ruby gem package manager
  • 8. Ruby anatomy Classes are CamelCased Methods are under_scored Generally no need for curly braces, parentheses, semicolon or return statement code more compact Comments =begin block comment =end # line comment Variables Constant @@classVariable @instanceVariable localVariable :symbol
  • 10. Ruby structure Modules Module::Class Mix-ins interfaces with functionality Namespace Subclass < Superclass Single inheritance only Files are named *.rb can hold many classes require ’file’ include Module searches $LOAD_PATH
  • 11. Access modifiers private Private to this instance (might be a subclass) You can’t specify the receiver, not even self protected Can be called by instances of the same class Eg use for comparators public FFA private :method or private (until end) The modifiers are methods, not keywords
  • 12. Testing Test::Unit::TestCase xUnit for ruby JRuby to test Java code? JtestR to invoke Code coverage might be an issue RSpec BDD
  • 13. Method signature - Java Method overloading Number of method signatures increases fast if flexibility is wanted
  • 14. Method signature – PL/SQL Named parameters Still have to change method signature too add parameters
  • 15. Method signature – Ruby Hash as optional parameter, not named parameters No need to change method signature Hash doesn’t need curly braces Method overload unavailable *args => arguments array
  • 16. More syntax examples =~ regexp matcher myString =~ /[0-9]+/ %w[] String array myArray = %w[ruby java haskell] {||} or do || end closures (and embedded variables) myHash.each { |k, v| puts k+’ is ‘+v } myHash.each do |key, val| puts “#{key} is #{val}” end
  • 17. Ruby on Rails MVC Framework “ Rails is the most well thought-out web development framework I’ve ever used. And that’s in a decade of doing web applications for a living. I’ve built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.” -James Duncan Davidson, Creator of Tomcat and Ant “ Rails is the killer app for Ruby.” Yukihiro Matsumoto, Creator of Ruby
  • 18. RoR principles Opinionated software Convention over configuration DRY REST GET /products #get all GET /products/42 #get id=42 POST /products #create Fast feedback loop just reload, no compile Rails itself is a gem
  • 19. Ruby on Rails concepts rails <appname> generates skeleton routes.rb ~struts-config.xml *.html.erb ~JSP Generators Generates model, view, controller, tests Partials (html.erb snippets) Plugins (instead of gems) Default database is sqlite3 (via JDBC for JRuby) Filters (defined in controller)
  • 20. RoR tools rails <appname> -d <database> script/generate scaffold Person name:string script/server script/console irb with access to the application script/dbconsole enter SQL script/server –debugger debugger in the code drops to console
  • 21. ActiveRecord O/R mapping Db migrations, dev, test, prod up and down database agnostic rake db:migrate config/database.yml Opinionated software primary key named id pluralization class Book => db books
  • 22. RoR model example class BlogPost < ActiveRecord::Base belongs_to :author has_many :comments validates_presence_of :title end comments table needs blog_post_id blog_posts table needs author_id New post need title field
  • 25. ActiveSupport::TestCase Inherits Test::Unit::TestCase Provides helpers, eg http calls <app>/test functional integration unit fixtures/fixtures.yml rake
  • 26. Jruby Motivation The JVM Sneak into the enterprise Reuse infrastructure Integrate with Java applications Performance and scalability
  • 27. JRuby on Rails Develop as Java Netbeans Eclipse Integrate with Java Call EJBs Use JMS queues Use JNDI Use JAAS Deploy on Java As *.war using warbler Rails deployer (JBoss, Glassfish)
  • 28. Java integration include Java / require ”java” include Java::JavaxSwing include_class &quot;javax.naming.InitialContext” require ”path/to/my.jar” prefix javaclasses to avoid name collisions String => JString include_class 'java.lang.String’ {|package,name| &quot;J#{name}&quot; } Method alias System.currentTimeMillis => System.current_time_millis Getters and setters behaves like attr_accessor fields
  • 29. IDE support Eclipse - DLTK (Dynamic Languages Toolkit) Eclipse foundation plugin Support for TCL, Python, Ruby No Rails Eclipse - Aptana RadRails RDT Ruby Editor Rails support generators/scripts Visual debug Testrunner Netbeans Official plugin
  • 30. Conclusion Ruby is sweet! Syntactic sugar Fun to work with Ruby is useful! Integrate with Java OO scripting Rails is probably fast enough Ruby is hard! “ Good programmers become better, bad programmers become worse” Test, test, test
  • 31. Thank you and Namaste
  • 32. Contact © Devoteam Consulting A/S. This document is not to be copied or reproduced in any way without the express permission of Devoteam Consulting. AUSTRIA BELGIUM CZECH REPUBLIC DENMARK FRANCE MOROCCO NETHERLANDS NORWAY POLAND SAUDI ARABIA SPAIN SWEDEN SWITZERLAND UNITED ARAB EMIRATES UNITED KINGDOM +46 (0)733-812135 Phone: [email_address] E-mail: Address Peter Sönnergren Person: CONTACT Author: Date: # ID: DOCUMENT

Editor's Notes