13

我正在学习Java。我已经学习并使用了 Ruby。Ruby 书籍总是讲述 Ruby 相对于 Java 的优势。但是肯定有一些优势,这就是为什么很多人(尤其是公司)使用 Java 而不是 Ruby 的原因。请说出 Java 相对于 Ruby 的绝对(不是哲学!)优势。

4

16 回答 16

18
  • 使用 Java 的开发人员比使用 Ruby 的开发人员多得多。
  • Java 中的许多现有库(这也有助于 JRuby)。
  • 静态类型检查(可以被视为优点和缺点)。
  • 必须维护的现有代码库。
  • 良好的工具支持。
  • 更多更深入的文档和教程。
  • 更多关于良好实践和陷阱的经验。
  • 更多的商业支持。这对公司来说很有趣。

许多这些优势是 Java 生态系统比围绕 Ruby 更成熟的结果。其中许多点是主观的,例如静态类型与动态类型。

于 2009-08-20T09:33:05.970 回答
12

I don't know Ruby very well, but I can guess the following points:

  • Java has more documentation (books, blogs, tutorial, etc.); overall documentation quality is very good
  • Java has more tools (IDEs, build tools, compilers, etc.)
  • Java has better refactoring capabilities (due to the static type system, I guess)
  • Java has more widespread adoption than Ruby
  • Java has a well-specified memory model
  • As far as I know, Java has better support for threading and unicode (JRuby may help here)
  • Java's overall performance is quite good as of late (due to hotspot, G1 new garbage collector, etc.)
  • Nowadays, Java has very attractive and cheap server hosting: appengine
于 2009-08-20T09:44:57.490 回答
7

请说出绝对的……Java 相对于 Ruby 的优势

程序员应该很少处理绝对问题。

我敢说,作为一项规则,静态类型 (Java) 比动态类型 (Ruby) 更有优势,因为它有助于更​​快地识别错误,并且不需要潜在的困难单元测试1)

智能地利用具有静态类型检查的强类型系统可以真正节省时间。


1)反对单元测试!但是好的单元测试很难,编译器可以极大地帮助减少必要的测试用例的数量。

于 2009-08-20T09:34:10.197 回答
5

Reason #1. There's a lot of legacy Java code out there. Ruby is new, there's not so many programmers who know it and even fewer who are good at it. Similarly, there is a lot more library code available for Java than Ruby.

So there may be Technical reasons Ruby is better than Java, but if you're asking for Business reasons, Java still beats it.

于 2009-08-20T09:34:16.093 回答
3

The Java Virtual Machine, which has had over a decade of improvements including:

  • just in time compilation in the HotSpot compiler (JIT - compiling byte code to native code)
  • a plethora of garbage collection algorithms and tuning parameters
  • runtime console support for profiling, management etc. of your application (JConsole, JVisualVM etc)
于 2009-08-20T10:15:09.303 回答
2

I like this Comparison(Found on link Given by Markus!Thanks!)... Thanks to all... i am also expecting some more discrete advantages

Java-Ruby Comparison


And its Great!!

于 2009-08-20T10:14:27.823 回答
2

The language.

My opinion is that the particular properties of the Java language itself lead us to the powerful capabilities of the IDEs and tools. These capabilities are especially valuable when you have to deal with very large code-base.

If I try to enumerate these properties it would be:

  • of course strong static typing
  • the grammar of language is a LALR(1) grammar - so it is easy to build a parser
  • fully qualified names (packages)

What we've got in the IDE so far, for example Eclipse:

  • great capabilities of exploring very large code bases. You can unambiguously find all references, call hierarhy, usages of classes or public and protected members - it is very valuable when you studying the code of the project or going to change something.
  • very helpful code editor. I noticed that when I writing code in the Eclipse's java editor I'm actually typing by hand only names of calsses or methods and then I press Ctrl+1 and editor generates a lot of things for me. And especially good that eclipse encourage you to write the usage of piece of code first and even before the code is aclually writen. So you do the method call before you create the method and then editor generates the method stub for you. Or you add extra arguments to the method or constructor in the place when you're invoking it - and editor change the signature for you. And enev more complicated things - you pass some object to the method that accept some interface - and if the object's class do not implement this interface - editor can do it for you... and so on. There's a lot of intresting things.

There is a LOT of tools for Java. As an example of a one great tool I want to mention Maven. Actually, my opinion is that the code reuse is really possible only when we have such a tool like Maven. The infrastructure built around it and integration with IDE make feasible very intresting thinsg. Example: I have m2eclipse plugin installed. I have new empty project in the Eclipse. I know that there is a class that I need to use (reuse actually) somewhere in the repositories, let say StringUtils for example. I write in my code 'StringUtils', Eclipse's editor tell me that there is no such class in the project and underlines it with red. I press Ctrl+1 and see that there is an ability to search this class in the public repository (actually in the index, not the repository itself). Some libs were found, I choose one of them at particular version and the tool downloads the jar, configures my project's calsspath and I alredy got all that I need.

So it's all about programmer's productivity.

The JVM.

My opinion is that the JVM (Sun's HotSpot particularly) is a one of the most intresting pieces of software nowadays. Of course the key point here is a performance. But current implementation of HotSpot JVM explores very cutting edge ways to achieve such really great performance. It explores all possible advantages of just-in-time compiling over static, collects statistics of the usage of code before JIT-compile it, optimise when it possible virtual calls, can inline a lot more things that static compiler can, and so on. And the great thing here that all this stuff is in the JVM, but not in the language itself (as contrary with C# as example). Actually, if you're just learning the Java language, I strongly encourage you to learn the details of modern implementations of JVM, so you know what is really hurt performance and what isn't, and do not put unnecessary optimizations in the Java code, and do not afraid to use all possibilities of the language.

So... it's all about IDEs and tools actually, but by some reason we have them for Java not for any other language or platform (.NET of course is a great competitor in the Windows world).

于 2009-08-20T13:53:35.617 回答
2

This has probably been beaten to death, but my personal opinion is that Ruby excels at quickly created web apps (and frameworks) that are easy to learn, beautiful to read, and are more than fast enough for web apps.

Where Java is better suited for raw muscle and speed.

For example, I wrote a Ruby program to convert a 192 MB text file to a MongoDB collection. Ruby took hours to run. And the Ruby code was as simple/optimized as you could get (1.9.2).

I re-wrote it in Java and it runs in 4 minutes. Yes. Hours to 4 minutes. So take that for what it's worth.

于 2011-04-02T03:24:45.807 回答
2

Network effect. Java has the advantage of more people using Java. Who themselves use Java because more people use Java.

于 2011-04-04T00:01:02.117 回答
1

If you have to build a big software, you'll need to collaborate. By having a lot of programmers out there, you are sure that there will be someone that can be asked to maintain your software even if the original developers have left the company.

Static type checking and good Java IDE offer no magic and this is good for a lot of maintainer instead of Ruby.

于 2009-08-20T09:41:26.017 回答
1

It is not sufficient to indicate that java is statically typed and ruby is dynamically typed.

Correct me if I'm wrong, but does this cover the fact that in ruby you can add to and even change the program (class definitions, method definitions etc) at runtime? AFAIK you can have dynamically typed languages that are not "dynamic" (can be changed at runtime).

Because in Ruby you can change the program at runtime you don't know until you've actually run the program how it is going to behave, and even then you don't know if it will behave the same next time because your code may have been changed by some other code that called the code you're writing and testing.

This predictability is, depending on the context, the advantage of Java - one of the contexts where this is an advantage is when you have a lot of developers of varying skill levels working on a fairly large enterprise application.

于 2009-08-20T09:58:40.053 回答
1

IMHO, what one person considers an advantage might be a disadvantage for someone else. Some people prefer static typing while others like dynamic. It is quite subjective and depends largely upon the job and the person doing it.

I would say just learn Java and decide for yourself what its strong points are. Knowing both languages yourself beats any comparisons/advice some other person can give. And its usually a good thing to know another language, so you're not wasting your time.

于 2009-08-20T11:09:29.520 回答
1

Negatives for Java:

  • There is a lot of duplication in libraries and frameworks available for Java.
  • Java developers/communities tend to create over complicated solutions to simple problems.
  • There is a lot more legacy in Java to maintain.
  • Too much pandering to business users has introduced cruft that makes middle managers feel better. In other words, some philosophies in Java are more concerned with BS instead of getting the job done. This is why companies like to use Java.
  • You'll generally need to write more code in Java than Ruby.
  • It takes a lot more configuring/installing/setup to get a fully working Java development environment over Ruby.

Positives for Java:

  • Speed.
  • Documentation.
  • Lower level language than Ruby, which could be a good thing or a bad thing, depending on your needs.

None of my points are very scientific, but I think the differences in philosophy and personalities behind Java and Ruby is what makes them very different to each other.

于 2009-08-23T13:15:21.373 回答
0

Better performances

于 2009-08-20T09:34:57.777 回答
0

There are more choices:

  • Developers - lots to hire
  • Libraries - lots of wheels already invented.
  • IDE's - lots of development environments to choose from. Not only just vi/emacs + a shell.
  • Runtimes - if you for some reason do not like the JVM you use on the system, you can either download or buy another implementation and it will most likely Just Work. How many Ruby implementations are there?

Please note that this has nothing to do with the LANGUAGES as such :)

于 2009-08-21T07:57:01.890 回答
0

Reading up on this : Is Ruby as cross-platform as Java? made me realize at least one factual advantage of java over ruby:

The J2ME-compatible subest of java is more portable than ruby

as long as JRuby won't run on J2ME which may be forever

于 2009-08-21T08:02:59.647 回答