• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
roofimon@njug5
 

roofimon@njug5

on

  • 1,746 views

 

Statistics

Views

Total Views
1,746
Views on SlideShare
1,744
Embed Views
2

Actions

Likes
0
Downloads
56
Comments
0

2 Embeds 2

http://www.linkedin.com 1
https://www.linkedin.com 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    roofimon@njug5 roofimon@njug5 Presentation Transcript

    • NJUG 5.0
      • Jruby
      • Groory
      • พักกินข้าว
      • Java Update Java Fx
      • Ajax with Cold Fusion
      • VIOP may be
    • JRuby @ NJUG By Roofimon NJUG 5.0 May 11, 2008 “ roofx<at>hotmail<dot>com”
    • Knowledge Resources( ลอกมาจากไหน )
      • Jruby Wiki
      • http://wiki.jruby.org/wiki/Main_Page
      • JRuby : Not Just Another JVM Language InfoQ
      • http://www.infoq.com/presentations/qconsf-nutter-jruby
    • Agenda
      • Brief History of Scripting Language
      • Brief History of Ruby
      • Brief History of Jruby
      • Rails and Jruby on Rails
      • Jruby Java and Java Jruby
      • Jruby Enterprise Java
      • Jruby Spring Bean and Controller
      • Jruby Web Services
      • Deploy Jruby
      • Q and A, Surprise
    • Brief History of Scripting Lang.
      • First interactive shells were developed in the 1960s, shellscripts
      • Scripting languages became complex enough to be used to extend the application
      • Scripting languages have been interpretive rather than compiled languages
      • Types of scripting languages
          • Job control languages and shells, shellscript
          • Application-specific languages, macro
          • Web browsers, javascript
          • Web servers, PHP
          • General-purpose dynamic languages, Ruby Python
    • Brief history of Ruby
      • At that time ( 1993 ) there is no OO script language
      • Project must be code-named after a gemstone's name (àla Perl). So my friend came up with &quot;ruby&quot;
      • The Ideals of Ruby’s Creator
      • “ ruby is simple in appearance, but is very complex inside, just like our human body”
      • 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.
    • Taste of Ruby
      • Everything is Object
      • 5.times{ print &quot;We *love* Ruby--it's outrageous!&quot; }
      • public class HiFive{
      • public static void main(String args[]){
      • for(int I =0; I <= 4; i++){
      • System.out.println(“We are sick of typing”);
      • }
      • }
      • }
    • Taste of Ruby
      • Always open
      • class Numeric
      • def plus(x)
      • self.+x
      • end
      • end
      • temp = 5.plus 6
      • Code Block
      • def simple
      • puts 'Here comes the code block!'
      • yield
      • puts 'There was the code block!'
      • end
      • simple { puts 'Hooray! The code block is here!' }
      • » Here comes the code block!
      • Hooray! The code block is here!
      • There was the code block !   
      • [1,2,3].each { |element| print element }
    • Taste of Ruby Mixin Cool
      • module BarModule
      • def hello_world
      • puts &quot;Hello World&quot;
      • end
      • end
      • class BaseClass
      • def class_method
      • puts &quot;In class method&quot;
      • end
      • end
      • class Foo < BaseClass
      • include BarModule
      • end
      • f = Foo.new
      • f.class_method
      • f.hello_world
    • JRuby on Rails
      • History of Rails
      • First Released on 2004 (Spring 1.0)
      • By David Heinemeier Hansson from his work on Basecamp
      • The fundamental Ruby on Rails principles include Convention over Configuration (CoC) and Don't repeat yourself (DRY).
      • Jruby did it but on JVM
    • Why Jruby on Rails
      • Performance
      • Unicode?
      • Thread (Not Green Thread)
      • Existing Library from Java
      • Still can use Ruby coding style, cool
      • Oracle Mix saids Jruby is the best way
    • Brief History of Jruby
      • Jruby was originally created by Jan Arne Petersen, in 2001
      • JRuby is a Java implementation of the Ruby interprete
      • In September 2006 , Sun Microsystems hired Enebo and Nutter to work on JRuby full time.
      • From 2006, users can port RoR(0.9) application to Jruby without any changes
      • Microsoft also hired the creator of IronRuby
    • Brief History of Jruby
      • JRuby 1.1 was released on April 5 2008
      • Highlights:
        • reduced memory consumption (permgen)
        • stat()/lstat() 300% faster
        • improved startup time
    • Jruby Java (Most Important)
      • Java Resources
        • Classes
        • Primatives
        • Array
      • Extend Java
        • Interfaces
        • Classes
      • Java Collection
    • Jruby Java (Class)
      • include_class(&quot;java.util.HashMap&quot;) {|pkg,name| &quot;JHashMap&quot;}
      • m = JHashMap.new
      • m.put &quot;hello&quot;, &quot;world&quot;
      • m.put &quot;goodbye&quot;, &quot;life&quot;
      • puts m.get(&quot;hello&quot;)
      • iter = m.keySet.iterator
      • while iter.hasNext
      • key = iter.next
      • puts &quot;#{key}=#{m.get(key)}&quot;
      • end
    • Jruby Java (Primative)
      • b1 = Java::byte
      • b2 = java.lang.Byte::TYPE
      • Working with primitives from JRuby isn’t recommended
    • Jruby Java (Array)
      • Usually you only need to use arrays in the sense of creating them so you can send them in to Java code.
      • [1,2,3].to_java # new Object[] {new Integer(1),
      • # new Integer(2), new Integer(3)}
      • [1,2,3].to_java :byte # new byte[] {1,2,3}
      • [1,2,3].to_java :char # new char[] {1,2,3}
      • [1,2,3].to_java :float # new float[] {1,2,3}
      • # etc
      • [&quot;str&quot;, &quot;str2&quot;].to_java java.lang.String # new String[]{&quot;str&quot;,&quot;str2&quot;}
    • Jruby Java
      • require 'java'
      • include_class 'java.util.TreeSet'
      • set = TreeSet.new
      • set.add &quot;foo&quot;
      • set.add &quot;Bar&quot;
      • set.add &quot;baz&quot;
      • set.each do |v|
      • puts &quot;value: #{v}&quot;
      • end
      • value: Bar
      • value: baz
      • value: foo
    • Extend Java by using Interface
      • package com.example;
      • public interface ISpeaker {
      • public void say(String msg);
      • public void addOne(String from);
      • }
      class CallJava include ISpeaker def initialize super @count = 0 end def say(msg) puts &quot;Ruby saying #{msg}&quot; end def addOne(from) # m.synchronize { @count += 1 puts &quot;Now got #@count from #{from}&quot; # } end end
    • Extend Java by using Class
      • Due to Jruby and Ruby are always Open so
      • class FooStream < java.io.OutputStream
      • def write(p)
      • puts p
      • end
      • end
      • s = java.io.BufferedOutputStream.new(FooStream.new)
      • s.write([1,2,3].to_java(:byte), 0, 3)
      • s.flush
    • Jruby Java (Most Important)
      • Collections.sort(foos, new Comparator() {
      • public int compare(Object o1, Object o2) {
      • return ((FooObject)o1).getName().compareTo(((FooObject)o2).getName());
      • }
      • });
      foos.sort_by {|o| o.name} Of course, if you have Facets or Rails loaded you can do it like this: foos.sort_by &:name
    • Jruby Java (Most Important)
      • Collections.sort(foos, new Comparator() {
      • public int compare(Object o1, Object o2) {
      • return ((FooObject)o1).getName().compareTo(((FooObject)o2).getName());
      • }
      • });
      foos.sort_by {|o| o.name} Of course, if you have Facets or Rails loaded you can do it like this: foos.sort_by &:name
    • J ava Jruby (S….)
      • Java 6 (using JSR 223: Scripting)
      • Embedding with Bean Scripting Framework (BSF)
      • Jruby Runtime
    • Jruby Enterprise Bean
      • Create EJB3 with Jruby
      • Bloody hard
      • In case we have Active Record Services but would like to wrap them with java
      • Create Wrapper Class which using low-level integrated with jRuby
    • Jruby Spring
      • Spring 2.0 introduces comprehensive support for
        • JRuby 0.9 / 1.0
        • Groovy 1.0 / 1.5
        • BeanShell 2.0
      • Each of the supported languages has a corresponding <lang:language/> element:
        • <lang:jruby/> (JRuby)
        • <lang:groovy/> (Groovy)
        • <lang:bsh/> (BeanShell)
    • Jruby Spring Bean
        • require 'java'
        • class RubyMessenger
        • include org.springframework.scripting.Messenger
        • def setMessage(message)
        • @@message = message
        • end
        • def getMessage
        • @@message
        • end
        • end
        • # this last line is not essential (but see below)
        • RubyMessenger.new
    • Jruby Spring Bean
        • <lang:jruby id=&quot;messageService&quot;
        • refresh-check-delay=&quot; 3000 &quot;
        • script interfaces=“xxx.scripting.Messenger&quot;
        • script-source=&quot; classpath:RubyMessenger.rb &quot;>
        • <lang:property name=&quot;message&quot; value=&quot;Hello World!&quot; />
        • </lang:jruby>
    • Jruby Spring Controller
        • require 'java'
        •  
        • include_class 'org.springframework.web.servlet.ModelAndView'
        • include_class 'org.springframework.web.servlet.mvc.Controller'
        •  
        • class MyController <Controller
        • def handleRequest ( request, response )
        • puts &quot;I'm in Ruby&quot;
        • mav = ModelAndView.new @@resultView
        • mav.addObject ( &quot;key&quot;,&quot;value&quot; )
        •     return mav
        • end
        • def setResultView ( resultView )
        • @@resultView = resultView
        • end  
        • def toString
        • return &quot;MyController in Ruby&quot;
        • end
        • end  
        • # needed by spring
        • MyController.new
    • Jruby Spring Controller
        • <lang :jruby id=&quot;myController&quot;
        • refresh-check-delay=&quot;3000“
        • script-source=&quot;/WEB-INF/Ruby/MyController.rb&quot;
        • script-interfaces=“xxxx.servlet.mvc.Controller&quot; >
        • <lang :property name=&quot;resultView&quot; value=&quot;view&quot; />
        • </lang :jruby >
    • Sample Application
      • Install Rails(1.8.6) on Jruby
      • Create Project
      • Active Records
      • Scaffolds
      • Controller
      • Active View
      • Deploy (GlassFish V3)
    • EJB back-end Rails Application
      • Install Rails(1.8.6) on Jruby
      • Create Project
      • Active Records
      • Scaffolds
      • Controller
      • Active View
      • Deploy (GlassFish V3)