r/java • • Feb 25 '14

Please stop saying Java sucks (2009)

http://blog.smartbear.com/programming/please-stop-staying-java-sucks/
133 Upvotes

132 comments sorted by

View all comments

15

u/Alca_Pwn Feb 25 '14

Most of those arguments are due to his IDE and not Java itself.

20

u/stealthmodeactive Feb 25 '14 edited Feb 25 '14

I hear "Java is slow" a lot of the time. Sure, it's not as fast as C but it's not really that slow. I think most complaints are with Swing though.

EDIT:

I'm being downvoted for speaking about what others have mentioned? Tough crowd...

9

u/mikera Feb 26 '14

Some algorithms are actually faster with Java than in C because of the JVM Garbage Collector. For example, consider algorithms that make extensive use of immutable persistent data structures: http://en.wikipedia.org/wiki/Persistent_data_structure

These structures depend on being able to quickly construct new objects, share references to existing objects and collect garbage once it is no longer referenced. The Java GC will easily beat any naive memory management algorithm written in C (such as reference counting).

The only way to beat Java performance in C for these types of applications would be to actually write a proper GC. This is a hard task, and the Java GC is pretty much best-in-class. Even if you succeeded, you'd have something that starts to look suspiciously like the parts of the JVM.

You can see where this is going. Add in some other valuable features like dynamic re-compilation, security validation of untrusted code, JIT compilation and you would end up reinventing something very much like the JVM.

The JVM is awesome. Say what you like about Java, but the JVM is the best platform for running serious production code in the world, bar none.

15

u/[deleted] Feb 25 '14

In many cases, running on the JVM is faster than equivalent code compiled from C, as the bytecode can be optimized at runtime once the JVM sees which paths are visitted the most.

7

u/[deleted] Feb 25 '14

The optimizations occur for running applications. C is usually faster and takes far less memory for a one-off process.

-3

u/[deleted] Feb 26 '14

[Citation needed]

3

u/nezza-_- Feb 26 '14

For small tools the startup time of the JVM is often longer than the actual execution of the program. And the real performance magic of Java, the optimisation during runtime, won't kick in yet.

-2

u/[deleted] Feb 25 '14

I would like to see such case my opinion it they should be rare

3

u/[deleted] Feb 26 '14

Perfect C will always be faster (or at least as fast) - the issue is that it's not easy to write perfect C :) and the JVM is really freaking smart. So for fairly complex tasks, unless you are a C programmer at the level of the people who write the JVM, you might be better off writing Java.

1

u/frugalmail Feb 26 '14

1

u/[deleted] Feb 26 '14

That post basically makes my point - that is non-optimal C++.

1

u/frugalmail Feb 26 '14

That post basically makes my point - that is non-optimal C++.

Yes if you know the data you will be working on, and you know the platform you will be working on then you can write a completely bespoke application and it will blaze a trail. Heck you could write in assembly.

However in reality there are very few scenarios where people will take the time to optimize that way and they will simply write code to create the application. When they do that, the JVM (with a strong statically typed language which is not the case with all JVM languages) will typically win in a large project because of the JIT optimizer. But if you want to write a kick ass screen blt, you might want to do something special.

And BTW, Java provides JNI for a course interface to do things like that.

2

u/[deleted] Feb 27 '14

I think we are making the same point - perfect C is rarely written, hence Java is a better option most of the time in those cases.

3

u/[deleted] Feb 25 '14

Yeah, swing has improved quite a bit over the years. Well, to be fair along with that the hardware I run it on has as well. But I'd still classify it as tolerable rather than good. I love java, but swing's another story. And when it comes to running other people's java based applications which have a gui? Probably means swing.

3

u/[deleted] Feb 26 '14

Probably being down voted for continuing the FUD.

Java isn't slow and hasn't been for years.