File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ruby and the fly likes Why would I Ruby when I can do everything in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Why would I Ruby when I can do everything in Java?" Watch "Why would I Ruby when I can do everything in Java?" New topic

Why would I Ruby when I can do everything in Java?

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
A friend was telling me that RoR would be the future. But then I said, I think not. I told him, if he could give me something that I can do in Ruby that I cannot do in Java, then I would go learn Ruby. So far, what I always intend to do with a language is

- Create a desktop App
- Create a mobile app
- Create a web app

of which I can all do in Java. Ruby is just good for the web as I can see it. I could be wrong though... What do you guys think?

SCJP 1.5
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
So why aren't you programming in Assembly, then?

Seriously, it's not that Ruby would provide you with something you couldn't do with Java but rather that some things can be done better or faster with Ruby than with Java. And vice versa.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

It would be better that you learn it and then decide which is better.

sergio mendez-rueda
Ranch Hand

Joined: May 12, 2005
Posts: 37
Hi @timothy sam,
<quote>if he could give me something that I can do in Ruby that
I cannot do in Java, then I would go learn Ruby
<quote>"If it doesn't exist, make it!"</quote>make it!
Here "the something-ruby":
We want to write a function that generates accumulators--
a function that takes a number n, and returns a function
that takes another number i and returns n incremented by i.
(That's incremented by, not plus. An accumulator has to accumulate.)
p.s. number => java-jargon: the function must be "generic"

viel spass(hoffentlich kannst du dieses Problem knacken:-))
def foo (n) lambda {|i| n += i } end WOOOOO!!!
please, post your java funtion!!!
Ken Anderson says that the following code is about as close as you
can get in Java:
public interface Inttoint { public int call(int i); }
public static Inttoint foo(final int n) {
return new Inttoint() {
int s = n;
public int call(int i) {
s = s + i;
return s; }};
This falls short of the spec because it only works for integers.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

[I am not an RoR developer or advocate]

Why would I Ruby when I can do everything in Java?
  • Because you want to
  • Because being a geek means learning new technology is great fun
  • Because your boss told you to
  • Because scripting langauges are fun

  • I could go on. Also, you seem to be making a common mistake when speaking about Ruby and RoR. Ruby is a lanaguage. RoR is a web framework that uses the Ruby language.

    Also note that you can do Desktop apps using Ruby:

    And if you use JRuby, you can use Swing or SWT/JFace.

    GenRocket - Experts at Building Test Data
    Justin Gehtland
    Ranch Hand

    Joined: Jan 30, 2007
    Posts: 31
    IMHO, you would choose Ruby or Java based on how much time and effort you would spend in that language on a project and the overall quality of the result you would expect for that investment. For certain applications, Ruby (and Rails) will let you work faster and end up with higher quality code. The same is true for Java.

    Here's a short list of factors I would use to determine if the app was right for Ruby/Rails:

  • its a web app, like an ecommerce site or a social networking site, with a lot of custom ajax pieces
  • it doesn't need cross database transactions
  • it is going to have to change a lot both during production and after release due to changing requirements
  • I have a small dev team (say, four or less)
  • I have a certain amount of control, or at least input, on the database schema and the deployment environment

  • The first criteria (for type of web app) is not really a criteria as much as an indicator. We've done Ruby and Rails for lots of projects that weren't ecommerce or social networking apps, but if that's the gig, the rest of the criteria are less important.
    Timothy Sam
    Ranch Hand

    Joined: Sep 18, 2005
    Posts: 751
    Thank you for your replies. I am downloading it right now, and see if I get to like it.
    Chris Stehno
    Ranch Hand

    Joined: Feb 26, 2001
    Posts: 180
    Ten years ago when Java was "the new kid in town" there was a lot of talk about it and a lot of controversy. The old-school C/C++ programmers poo-pooed it as being a toy or just for the web.

    When I found myself saying similar things about Ruby and Ruby on Rails, I considered it a warning and started learning it. :-)

    I have been using Ruby for only a short while and am starting to use it for all kinds of automation scripts. I have also started learning RoR and am blown away by its powerful simplicity. What would take a week to do in Java (even with Hibernate and Spring) took a day with RoR.

    Is it the right tool for every job, no. Is it another tool for your tool box? YES!

    There is also some interesting work closer to the JAVA_HOME :-). If you look at Groovy and Groovy on Rails (Grails)... they are providing a lot of what Ruby and RoR provides but with a more Java flavoring.

    Good times ahead :-)

    - Chris Stehno, SCPJ
    Roseanne Zhang
    Ranch Hand

    Joined: Nov 14, 2000
    Posts: 1953
    Actually, Ruby and Java were born in the same year (1995)
    Ulf Dittmer

    Joined: Mar 22, 2005
    Posts: 42965
    Originally posted by sergio mendez-rueda:
    Here "the something-ruby":

    That doesn't prove much. Ruby has different language concepts than Java, so sometimes you can't do things the same way; but it's certainly possible to do them.

    Just about all programming languages are alike in that they are Turing complete, so there's nothing one language can do that another positively can't. The differences are in the kinds of problems that are easy in one vs. easy in the other, as Lasse pointed out. That depends a great deal on what you'd use the language for, and thus can't be answered in general.
    Alex Lewis

    Joined: Jun 20, 2007
    Posts: 3
    I think of it as I read from a book. Ruby syntax is made for being easy for the human brain. Java, and many other languages, are made to be easier for the compiler/computer to learn. Now which one will get twice as fast in 18 months? Computers can handle any extra work. Just look at some Ruby code. I was amazed how readable it was before even knowing the language.
    I agree. Here's the link:
    subject: Why would I Ruby when I can do everything in Java?
    It's not a secret anymore!