Link2Ib wrote:
I've made some little programs in Java with GUIs and it seems like Swing really sucks the performance out of everything.
Creating a fast, responsive GUI in any language is a bit of an art. I won't argue that Swing is fast, but I've seen and written enough Swing apps to know that it usually isn't the library causing the problems.
BTW, you may want to take a look at the changes in Java 6. Swing changeg quite a bit since Java 5.
Link2Ib wrote:
The fact is that no matter what, even in a best case scenario the Java code is still running through a VM, even if the difference is hardly noticeable on a faster computer.
Unfortunately, this frequently given arguement is flawed. It is probably easiest demonstrate why by exposing a hole in the similiar arguement that hand-written assembly code is always faster than the code generated by a compiler. Taken at face value, it would seem true that an experienced assembly language programmer should be able to write better/faster code than a compiler. However, it turns out that the compiler writers know all the same tricks as the assembly language programmers (often more) and the well written compiler is able to do a much better job at analyzing the code (in much the same way that deep blue would kick all of our collective butts in a game of chess -- including the authors). Hennessy and Patterson, who created the MIPS and RISC architectures, discuss this in their book.
Now you might be saying to yourself that this isn't exactly an apples/oranges comparison (and you'd be right). However, by delaying compilation until runtime, a JIT compiler is able to take advantedge of optimizations that are not available to a normal compiler at compile time. Also, the Java language doesn't have pointers which makes it possible to optimizations that are next to impossible in other languages.
Anyways, I'm not saying Java is faster. On average, I suspect it is about 10-20% slower than C++ or Ada and probably 15-30% slower than C or Fortran. However, you'll be hard pressed to notice the difference in most apps, especially networked or disk bound applications. As with the GUI example above, more often than not, any perceived slowness is the fault of the programmer. I'll create a second post supporting this postion in a second.
* Outside of the well known issue with trig functions on x86 hardware.