# Ruby for Java Folks?

**URL:** <https://rubytalk.org/t/ruby-for-java-folks/25792>\
**Category:** ruby-talk\
**Created:** [15 March 2006 16:58 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792 "2006-03-15T16:58:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Schwartz1](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@Eric\_Schwartz1](https://rubytalk.org/u/Eric_Schwartz1)\
**Post date:** [15 March 2006 16:58 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/1 "2006-03-15T16:58:46Z")

</div>

I've agreed to give a brief talk on Ruby for the Pikes Peak Java  
Developers Group. I've done stuff like this before at work, but that  
was for a crowd coming from a background of shell scripting and Perl.  
I'm not much of a Java guy myself, but I know there's a lot of overlap  
between the Java and Ruby communities. I can easily spend 45+ minutes  
on Ruby no matter what, but if any of you have any suggestions on what  
an audience of Java programmers would be interested in, I'd welcome  
suggestions.

Here's some topics I plan to cover:

\* Everything's a class.  
\* Interpreted vs. compiled, and how that affects  
&nbsp;&nbsp;both language design and performance.  
\* Static vs. dynamic typing, leading into  
\* Duck typing.  
\* Modifying library classes.  
\* Modifying individual objects-- emphasis on  
&nbsp;&nbsp;using this for testing frameworks.  
\* Briefly cover Test::Unit and maybe JRuby.

This is all subject to modification. I may bring Test::Unit in  
earlier, when I tart talking about duck typing. I don't, I think,  
want to get into too much comparison between the two languages-- these  
are very knowledgable Java people, much more so than I am. My best  
approach, I think, is simply to present Ruby to them as a fun  
language, perhaps for prototyping Java solutions, ideally as an end in  
itself.

Any ideas on what else I should cover, or if I should de-emphasize  
some of what I listed above would be welcome.

-=Eric

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [15 March 2006 17:16 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/2 "2006-03-15T17:16:13Z")

</div>

> I've agreed to give a brief talk on Ruby for the Pikes Peak Java  
> Developers Group. I've done stuff like this before at work, but that  
> was for a crowd coming from a background of shell scripting and Perl.  
> I'm not much of a Java guy myself, but I know there's a lot of overlap  
> between the Java and Ruby communities. I can easily spend 45+ minutes  
> on Ruby no matter what, but if any of you have any suggestions on what  
> an audience of Java programmers would be interested in, I'd welcome  
> suggestions.

One possibility might be to show them JRuby? I used to do  
that with Jython. Show Java people Python by running Jython  
in interactive mode, and creating Swing or AWT windows right  
from the command line. I presume JRuby has an IRB. . . .

If JRuby works like Jython, you can load any ol' compiled  
Java class and instantiate Java objects and call methods on  
them interactively.

Back when I was programming in Java, I did as much coding in  
Jython as possible, including writing all my unit tests in  
PyUnit instead of JUnit. Far less tedious, from my point of  
view. These days, I'd want to use JRuby instead of Jython...

Well, just a thought. . .

Regards,

Bill

> **···**
>
> From: "Eric Schwartz" \<emschwar@fc.hp.com\>

---

<div class="post-metadata">

**Author:** ![Patrick\_Chanezon](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Patrick\_Chanezon](https://rubytalk.org/u/Patrick_Chanezon)\
**Post date:** [15 March 2006 17:21 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/3 "2006-03-15T17:21:57Z")

</div>

One topic that I haven't seen covered anywhere and would find useful is a  
mapping between java and ruby libraries, organised by application domain,  
and their differences in functional coverage: java is more than a language,  
it's a platform and people spend more time learning libraries than the core  
language.  
One common question for a java developer starting ruby is: in java I would  
use this lib to perform that task, what should I use in ruby?  
I guess we should have a wiki page with that.

For example  
domain: http  
jakarta http-utils -\> http-access2, open-uri

P@

> **···**
>
> On 3/15/06, Eric Schwartz \<emschwar@fc.hp.com\> wrote:
> 
> > I've agreed to give a brief talk on Ruby for the Pikes Peak Java  
> > Developers Group. I've done stuff like this before at work, but that  
> > was for a crowd coming from a background of shell scripting and Perl.  
> > I'm not much of a Java guy myself, but I know there's a lot of overlap  
> > between the Java and Ruby communities. I can easily spend 45+ minutes  
> > on Ruby no matter what, but if any of you have any suggestions on what  
> > an audience of Java programmers would be interested in, I'd welcome  
> > suggestions.
> > 
> > Here's some topics I plan to cover:
> > 
> > \* Everything's a class.  
> > \* Interpreted vs. compiled, and how that affects  
> > &nbsp;&nbsp;both language design and performance.  
> > \* Static vs. dynamic typing, leading into  
> > \* Duck typing.  
> > \* Modifying library classes.  
> > \* Modifying individual objects-- emphasis on  
> > &nbsp;&nbsp;using this for testing frameworks.  
> > \* Briefly cover Test::Unit and maybe JRuby.
> > 
> > This is all subject to modification. I may bring Test::Unit in  
> > earlier, when I tart talking about duck typing. I don't, I think,  
> > want to get into too much comparison between the two languages-- these  
> > are very knowledgable Java people, much more so than I am. My best  
> > approach, I think, is simply to present Ruby to them as a fun  
> > language, perhaps for prototyping Java solutions, ideally as an end in  
> > itself.
> > 
> > Any ideas on what else I should cover, or if I should de-emphasize  
> > some of what I listed above would be welcome.
> > 
> > -=Eric
> 
> --  
> Patrick Chanezon, AdWords API evangelist  
> [http://blog.chanezon.com/](http://blog.chanezon.com/)
> 
> > **[Genel bakış  |  Google Ads API  |  Google for Developers](https://developers.google.com/google-ads/api/docs/start?csw=1&hl=tr)**
> >
> > Büyük Google Ads hesaplarını ve kampanyalarını yönetecek araçlar oluşturun.

---

<div class="post-metadata">

**Author:** ![Gregory\_Seidman](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Gregory\_Seidman](https://rubytalk.org/u/Gregory_Seidman)\
**Post date:** [15 March 2006 17:30 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/4 "2006-03-15T17:30:51Z")

</div>

} I've agreed to give a brief talk on Ruby for the Pikes Peak Java  
} Developers Group. I've done stuff like this before at work, but that  
} was for a crowd coming from a background of shell scripting and Perl.  
} I'm not much of a Java guy myself, but I know there's a lot of overlap  
} between the Java and Ruby communities. I can easily spend 45+ minutes  
} on Ruby no matter what, but if any of you have any suggestions on what  
} an audience of Java programmers would be interested in, I'd welcome  
} suggestions.  
}  
} Here's some topics I plan to cover:  
}  
} \* Everything's a class.

Well, technically, everything's an object, including classes. This leads  
into everything else, so I agree that it should be first.

} \* Static vs. dynamic typing, leading into  
} \* Duck typing.

I moved these two up. It is one of the most crucial differences between  
Java and Ruby.

} \* Interpreted vs. compiled, and how that affects  
} both language design and performance.  
} \* Modifying library classes.  
} \* Modifying individual objects-- emphasis on  
} using this for testing frameworks.

These are all pretty closely related. The unifying concept is that the set  
of methods on an object can be modified easily. Ruby is very similar to  
JavaScript in this, though I like Ruby syntax better.

} \* Briefly cover Test::Unit and maybe JRuby.  
[...]  
} Any ideas on what else I should cover, or if I should de-emphasize  
} some of what I listed above would be welcome.

An incredibly important idea is that everything written in Ruby is executed  
code. When a class definition is read, for example, it defines the class by  
executing code, not by being compiled. That is why and how things like  
attr\_accessor work. It also means that when requiring files or including  
modules order can matter, unlike Java's import (which just imports a  
namespace).

} -=Eric  
--Greg

> **···**
>
> On Thu, Mar 16, 2006 at 01:58:46AM +0900, Eric Schwartz wrote:

---

<div class="post-metadata">

**Author:** ![James\_H](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@James\_H](https://rubytalk.org/u/James_H)\
**Post date:** [15 March 2006 18:58 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/5 "2006-03-15T18:58:46Z")

</div>

Hi Eric.

It's safe to assume that your viewers will have seen this, and perhaps  
you as well, but the Ruby Doc has a slide series entitled "10 Things  
Every Java Programmer Should Know About Ruby"  
([http://www.ruby-doc.org/docs/10%20Things%20Every%20Java%20Programmer%20Should%20Know%20About%20Ruby/10things.tgz](http://www.ruby-doc.org/docs/10%20Things%20Every%20Java%20Programmer%20Should%20Know%20About%20Ruby/10things.tgz)).

It might prove useful for you insofar as what the author, Jim Weirich,  
felt important to convey. Perhaps it'll help you fine tune your  
presentation.

---

<div class="post-metadata">

**Author:** ![Wilson\_Bilkovich](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/wilson_bilkovich/32/8247_2.png) [@Wilson\_Bilkovich](https://rubytalk.org/u/Wilson_Bilkovich)\
**Post date:** [15 March 2006 20:57 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/6 "2006-03-15T20:57:25Z")

</div>

How about working through some of the examples from Refactoring by  
Martin Fowler, or Smalltalk Best Practice Patterns by Kent Beck, using  
both Java and Ruby side-by-side?

One thing I really like about Ruby is that certain tasks (like  
enumeration) have much less code overhead than in Java, which promotes  
nice, small methods that are easy to refactor or rework. Even if it's  
only 6 lines, there's some mental resistance to setting up a loop in  
Java.

> **···**
>
> On 3/15/06, Eric Schwartz \<emschwar@fc.hp.com\> wrote:
> 
> > I've agreed to give a brief talk on Ruby for the Pikes Peak Java  
> > Developers Group. I've done stuff like this before at work, but that  
> > was for a crowd coming from a background of shell scripting and Perl.  
> > I'm not much of a Java guy myself, but I know there's a lot of overlap  
> > between the Java and Ruby communities. I can easily spend 45+ minutes  
> > on Ruby no matter what, but if any of you have any suggestions on what  
> > an audience of Java programmers would be interested in, I'd welcome  
> > suggestions.
> > 
> > Here's some topics I plan to cover:
> > 
> > \* Everything's a class.  
> > \* Interpreted vs. compiled, and how that affects  
> > &nbsp;&nbsp;both language design and performance.  
> > \* Static vs. dynamic typing, leading into  
> > \* Duck typing.  
> > \* Modifying library classes.  
> > \* Modifying individual objects-- emphasis on  
> > &nbsp;&nbsp;using this for testing frameworks.  
> > \* Briefly cover Test::Unit and maybe JRuby.
> > 
> > This is all subject to modification. I may bring Test::Unit in  
> > earlier, when I tart talking about duck typing. I don't, I think,  
> > want to get into too much comparison between the two languages-- these  
> > are very knowledgable Java people, much more so than I am. My best  
> > approach, I think, is simply to present Ruby to them as a fun  
> > language, perhaps for prototyping Java solutions, ideally as an end in  
> > itself.
> > 
> > Any ideas on what else I should cover, or if I should de-emphasize  
> > some of what I listed above would be welcome.

---

<div class="post-metadata">

**Author:** ![Pistos\_Christou1](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Pistos\_Christou1](https://rubytalk.org/u/Pistos_Christou1)\
**Post date:** [16 March 2006 14:41 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/7 "2006-03-16T14:41:34Z")

</div>

Eric Schwartz wrote:

> Any ideas on what else I should cover, or if I should de-emphasize  
> some of what I listed above would be welcome.

Personally, I still think Stephen Waits' "Learn Ruby" slideset [1] is  
really good for introducing or showing experienced programmers what Ruby  
can do. I'd recommend at least skimming that, even if only to see what  
topics you forgot to include. I point out that the Learn Ruby slideset  
is predominantly code snippets and irb transcripts -- and I think that's  
a good thing.

[1]: [http://www.waits.net/~swaits/LearnRubyTalk/learnruby.html](http://www.waits.net/~swaits/LearnRubyTalk/learnruby.html)

Patrick Chanezon mentioned building a mapping of Java stdlib to Ruby  
stdlib. I think this is a good idea, too, not just for your talk, but  
Rubydom in general.

Pistos

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Julian\_I\_Kamil](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@Julian\_I\_Kamil](https://rubytalk.org/u/Julian_I_Kamil)\
**Post date:** [15 March 2006 19:33 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/8 "2006-03-15T19:33:46Z")

</div>

And let me add another one: "Coming to Ruby from Java", by Francis  
Hwang

[http://books.rubyveil.com/books/ComingToRubyFromJava/Introduction/ComingToRubyFromJava](http://books.rubyveil.com/books/ComingToRubyFromJava/Introduction/ComingToRubyFromJava)

Best regards,

Julian I. Kamil \<[julian.kamil@gmail.com](mailto:julian.kamil@gmail.com)\>  
[http://pandora.rubyveil.com/](http://pandora.rubyveil.com/) - Pandora Publisher  
[http://books.rubyveil.com/](http://books.rubyveil.com/) - The Ruby Bookshelf

---

<div class="post-metadata">

**Author:** ![Eric\_Schwartz1](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@Eric\_Schwartz1](https://rubytalk.org/u/Eric_Schwartz1)\
**Post date:** [15 March 2006 22:28 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/9 "2006-03-15T22:28:47Z")

</div>

"Wilson Bilkovich" \<wilsonb@gmail.com\> writes:

> How about working through some of the examples from Refactoring by  
> Martin Fowler, or Smalltalk Best Practice Patterns by Kent Beck, using  
> both Java and Ruby side-by-side?

Most of my good books (like Refactoring) are packed up, alas! But  
I'll see if I can't come up with some simple examples of "Here's how  
you do it in Java, now here's Ruby". I want to avoid appearing to  
diss Java at all; these are presumably smart people who don't care to  
have advocacy thrown at them; I just want to give them info.

> One thing I really like about Ruby is that certain tasks (like  
> enumeration) have much less code overhead than in Java, which promotes  
> nice, small methods that are easy to refactor or rework. Even if it's  
> only 6 lines, there's some mental resistance to setting up a loop in  
> Java.

Yeah, I have to admit that, having done some C recently (had to  
interface with a new device driver, and didn't want to learn how to do  
ioctls in Ruby at the time), I hate doing C/Java-style for loops like  
this:

String fileNames = new File( "/home/emschwar" ).list();  
for(int i=0; i \< fileNames.length; i++) {  
&nbsp;&nbsp;&nbsp;System.out.println("directory entry named [" + fileNames[i] + "]");  
}

There's no real reason for it, but it focuses my mind more on the  
array (how I set it up, how I'm iterating over it) when I'm reading it  
than in the Ruby below:

Dir.entries('/home/emschwar').each { |e|  
&nbsp;&nbsp;&nbsp;puts "directory entry named [#{e}]"  
}

Here, I'm more focused on what I'm doing to each element-- this  
reminds me a lot more of Perl's map (and Lisp's mapcar) function, but  
when I use Perl, I feel like I'm turning the iteration inside out;  
here it's just a much simpler way of doing the same for loop above.  
Without complaining about Java, showing how Ruby iteration eliminates  
the need for explicit iterators would certainly be powerful stuff.

(personally, I prefer do...end, but used {} here to make Java people  
feel more comfortable 🙂

-=Eric

---

<div class="post-metadata">

**Author:** ![Eric\_Schwartz1](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@Eric\_Schwartz1](https://rubytalk.org/u/Eric_Schwartz1)\
**Post date:** [15 March 2006 22:33 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/10 "2006-03-15T22:33:47Z")

</div>

"Patrick Chanezon" \<chanezon@gmail.com\> writes:

> One topic that I haven't seen covered anywhere and would find useful is a  
> mapping between java and ruby libraries, organised by application domain,  
> and their differences in functional coverage: java is more than a language,  
> it's a platform and people spend more time learning libraries than the core  
> language.

Right. The problem I have is that I'm, as I said, much more of a  
Perl/Ruby guy than a java one; they'll know standard (and useful,  
nonstandard) libraries better than I will.

> One common question for a java developer starting ruby is: in java I would  
> use this lib to perform that task, what should I use in ruby?  
> I guess we should have a wiki page with that.

That would be useful. I'm giving the talk on Tuesday, though (I  
volunteered as a last-minute replacement for the regular speaker who  
had to cancel), so if someone has information like that, I can use it,  
but I don't think I have time to develop it on my own.

-=Eric

---

<div class="post-metadata">

**Author:** ![Charles\_Nutter](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/charles_nutter/32/2567_2.png) [@Charles\_Nutter](https://rubytalk.org/u/Charles_Nutter)\
**Post date:** [15 March 2006 20:27 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/11 "2006-03-15T20:27:06Z")

</div>

I agree with what others have said about presenting Ruby, and I'd sure love  
to find a good presentation I could give my own Java devs.

I'd want it to cover:  
- Ruby the language, Objects, Class, cool stuff  
- How Java features map to Ruby...someone else mentioned this, and it would  
be a huge help, especially with examples  
- JRuby would be very useful for demonstrating how Java devs can start using  
Ruby today. A lot of shops have standardized on "Java Only" and this is a  
sneaky way to get Ruby into the mix. If anyone complains about a non-Java  
language being used, you just have to mention SQL, XML, JavaScript, and so  
on.

For the first item, I'd hope someone has a good hour-long walkthrough of  
Ruby and why it's cool. I don't know of any such document for the second  
one. Finally, we have some good demos in JRuby CVS that might help you with  
that last one.

> **···**
>
> --  
> Charles Oliver Nutter @ [headius.blogspot.com](http://headius.blogspot.com)  
> JRuby Developer @ [jruby.sourceforge.net](http://jruby.sourceforge.net)  
> Application Architect @ [www.ventera.com](http://www.ventera.com)

---

<div class="post-metadata">

**Author:** ![Christoph\_Hess](https://avatars.discourse-cdn.com/v4/letter/c/96bed5/32.png) [@Christoph\_Hess](https://rubytalk.org/u/Christoph_Hess)\
**Post date:** [16 March 2006 11:03 UTC](https://rubytalk.org/t/ruby-for-java-folks/25792/12 "2006-03-16T11:03:47Z")

</div>

> String fileNames = new File( "/home/emschwar" ).list();  
> for(int i=0; i \< fileNames.length; i++) {  
> &nbsp;&nbsp;System.out.println("directory entry named [" + fileNames[i] + "]");  
> }

> There's no real reason for it, but it focuses my mind more on the  
> array (how I set it up, how I'm iterating over it) when I'm reading it  
> than in the Ruby below:
> 
> Dir.entries('/home/emschwar').each { |e|  
> &nbsp;&nbsp;puts "directory entry named [#{e}]"  
> }

File yourFolder = new File("/home/emschwar");  
for (String n : yourFolder.list()) {  
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("directory entry named [" + n + "]");  
}

/// shorter:

for (String n : new File("/home/emschwar").list()) {  
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("directory entry named [" + n + "]");  
}

/// shorter:  
&nbsp;&nbsp;&nbsp;&nbsp;/// using jakarta-commons-IO + Java 5 static-imports  
&nbsp;&nbsp;&nbsp;&nbsp;/// I'm always using jakarta-commons

for (String n : list("/home/emschwar")) {  
&nbsp;&nbsp;&nbsp;&nbsp;out.println("directory entry named [" + n + "]");  
}

Greetings  
Christoph
