Following on from my previous article, the Java platform has an even greater image problem that is more than skin deep. Coming under yet another two-pronged attack, you’ll typically hear complaints falling into the two camps:
- Java is slow
- Java is a memory hog
The corollary being that Java on the desktop is infeasible for those without the patience of a saint. Funnily enough, in my experience, many people who have commented to me, “Andy, I don’t like Java because it’s slow” are the very same people who use Perl/Python/PHP. It suggests to me that not all the criticism is entirely objective! This article aims to discuss some of the criticisms aimed at Java and see whether they are justified.
Memory
To be honest, even the most faithful Java evangelist would have trouble believing that Java is light on memory usage (relatively speaking, of course). I don’t believe that it is, so I’m not going to pretend. Object-orientated languages typically have a slightly larger memory footprint as you have to carry around a lot of information about all your objects currently initialised. A large factor is simply the JVM itself. A simple “Hello world!” class of say a kilobyte will still require the entire JVM, and the several megabytes that entails. Yet, you must think about what you get for your money, so to speak. The JVM and the Java runtime classes are feature packed.
However, one man’s feature is another man’s bloat and I suppose this is where a lot of the debate stems from. When designing languages, you go either minimalist, and rely on the users to implement all the functionality they need; or you go for the opposite, and provide an extremely rich language where developers can rapidly produce software. As a Java developer, I don’t need to manage my memory programmatically: I can leave it all to the garbage collector. This is great for me, but not necessarily the most efficient way to manage memory. If you want to partake in old-school manual memory-management then you can do a certain amount (such as dereferencing your objects and then explicitly calling the garbage collector), but nothing as low-level as what C programmers would be accustomed to. There are other things you can do as a Java programmer to reduce the overhead such as using third-party libraries designed to be more efficient, such as fastutil or Javolution, which replace commonly used classes like the collections framework.
It’s worth being aware that the JVM by default doesn’t use all the available memory on a given system. This means that by default a Java application won’t overwhelm your system and cause heavy swapping and other such nastiness. Programs known to be memory intensive by nature, like scientific applications can in fact be limited by the JVMs conservative usage, and so many developers launch their Java apps with special JVM flags that permit Java to utilise additional memory.
Speed
To be fair, before I began looking into this, I had never thought that Java was the fastest language out there. I suppose, however, that because I’m still using Java, that I believe it’s fast enough. Assuming that C++ is the holy-grail in terms of performance because it’s so fast, then even if Java could achieve half it’s speed, it’s still fast! People seem to get so focussed on the milliseconds that they forget that if a task takes 0.01s in C++ and 0.02s in Java, then, “oh no”, it’s half as slow!
Yet, since mulling over this topic, I have found interestingly that Java has really made great gains in overall performance that can in fact put it on par with C++, if not a little quicker! There are various benchmarks that have reported Java algorithms running quicker than C++ equivalents. (Java Pulling Ahead, Java Faster than C++, FreeTTS case study) You will of course find many benchmarks finding the converse. What this shows is that they’re at least comparable which is enough for me to imply that Java is fast, and I’ll leave it to the benchmark zealots to fight over their nanoseconds.
I think Java is somehow still seen as an interpreted language; in fact, it does get compiled to native code using Just In Time (JIT) compilation. It is also a myth to think that JIT code is slower than pre-compiled code. The only difference is that bytecode gets JITed once its required (i.e., the first time a method is called – and the time is negligible) it then gets cached for subsequent calls. JIT code can benefit from all the same optimisations that pre-compiled can get, plus some more (from Lewis and Neumann, 2004):
- The compiler knows what processor it is running on, and can generate code specifically for that processor. It knows whether (for example) the processor is a PIII or P4, if SSE2 is present, and how big the caches are. A pre-compiler on the other hand has to target the least-common-denominator processor, at least in the case of commercial software.
- Because the compiler knows which classes are actually loaded and being called, it knows which methods can be de-virtualized and inlined. (Remarkably, modern Java compilers also know how to “uncompile” inlined calls in the case where an overriding method is loaded after the JIT compilation happens.)
- A dynamic compiler may also get the branch prediction hints right more often than a static compiler.
Even if it were slower, once again, you have to think what value for money you get per-clock cycle with Java. Many of the core classes are thread-safe as standard, for example; and let’s not forget free garbage collection. Also, that bit of code will run fine on all supported platforms without any additional effort. All the OS abstraction is done for you. That’s pretty incredible when you think about what it takes to actually pull off such a large abstraction layer like that.
Java Virtual Machine
The JVM once again causes controversy when evaluating Java’s speed. Java benchmarks typically discount the startup time of the JVM itself. Non-Java benchmarkers would consider this unfair, and not fully representative of the overall program performance. It’s a difficult debate. If I want to simply compare, say, raw Java Vector performance versus raw C++ STL vector performance, then why should we consider start-up times? Also, if I’m trying to profile algorithms within my program, again, why should start-up be useful in evaluating? But, if I’m comparing two programs that perform an equivalent task, I’d probably want to consider the overall time from initial execution to completion. Having said that, the larger the application, the less of an issue the JVM load times will be due to economies of scale. (Note, even this is getting better thanks to Class Data Sharing, amongst other things) One other thing to remember is that many Java applications are actually deployed as a Jar file (a glorified Zip file, essentially). You can execute the code within from the JVM directly – it therefore has to decompress the file first, and this obviously incurs a time penalty.
The Project Barcelona research group at Sun are coming up with some interesting technologies to improve the JVM in the future. That’s not to say that the current JVM hasn’t been improving steadily during each release. The Multi-tasking Virtual Machine (MVM) looks most promising as it’ll allow multiple Java applications to share the VM, reducing the overall burden on system resources. Ok, I know you can do this already on the current JVM, but it’s still a little raw. The MVM will be much more scalable and efficient. It seems to me that with such a system, you can finally run the JVM as a daemon on your system at startup, and then all subsequent Java programs you load will load as quickly as native apps. One can’t help but lose some optimism when you learn that the MVM may not even make it into Java 1.7 (Dolphin) due in the second half of 2007. I hope it does! In the meantime, you could to better than to look at some of the existing shared VMs like Janos, JKernel and Alta.
Java desktop
It’s on the desktop where many people form their opinions of Java, and it is here where people complain most about performance issues. The Swing toolkit is very powerful and rich, yet it is huge. Werner Randelshofer states that a Swing “Hello world!” program will require approximately 800 classes to be initialised before the user sees the infamous greeting. Yet, there is no shortage of Java developers who will tell you that Swing is fast.
Perceived performance
What those in the know will tell you is that Java in fact has a problem in perceived performance. You often hear about grey rectangles, unresponsive widgets, etc. The issue here is that Swing is perfectly responsive, until you hit a widget that triggers a task. The biggest trap Swing programmers fall into is that they don’t understand the threading model that is employed.
Here’s the science…
The Java designers decided not to make Swing components thread-safe, and instead opted for a single thread (known as the event-dispatch thread), to maintain the state of the GUI components. Therefore, your code that you want to run when a user clicks on a given button by default gets added to the EDT. If the code is something non-trivial, like loading a large file or querying a database, then this will block the EDT until it completes, resulting in an unresponsive GUI in the meantime. The remedy is to dispatch long tasks (i.e., anything likely to take > 0.25s) on their own thread, which frees up the EDT for doing purely GUI related tasks (see Ben Galbraith’s excellent tutorial).
The EDT approach is hardly exclusive to Java because it makes toolkit design much easier. You’ll find .Net’s Winforms opts for a similar model. The EDT is supposed to simplify things, yet it seems to be a common pitfall. Some one commented recently:
“… I may point out that Swing is not slow… The problem is that’s very easy to shoot yourself in the foot with Swing, but can happen with any toolkit, even those using native code. Well written Swing code can be as fast as a native application, if not faster.”
Shooting yourself in the foot
I was interested in this comment and decided to go off at a bit of a tangent here to examine if Java is really that prone to making unresponsive interfaces. I was discussing this with Jasper Potts from Xerto (producer of the visually impressive Java app, Imagery) and we got on to documentation:
“Swing itself is not slow, but that’s not to say that it’s that easy to write large applications that perform well. There is definitely room for some more articles on using Swing in the desktop… There is a real need for Swing books that tell you how to do things in the real world. [Desktop Java Live] is the first book I have come across that is trying to do that. Even all the books called “Advanced …”,”Extreme…”, etc., all they do is redo the Java [API] docs for the more advanced components. There are a few topics that just don’t seem to be documented at all well anywhere like the Focus System.”
Scott Delap, author of Desktop Java Live indulged me an a discussion on this topic too:
“Java/Swing being slow is one of those myths that has become embedded in the mindset of developers. I can easily write a desktop application in any language that is slow. I would suspect that 8 out of 10 developers that comment “Swing is slow” haven’t written a Swing app in at least 5 years. It is much like the Linux developer community labelling Microsoft as evil. Even if Microsoft became the best open source citizen tomorrow, it would take many years before the majority of developers would have this opinion of them. As far as countering the statement, I think the best rebuttal is the continuing production of quality desktop applications written in Java. The more there are the harder it is to argue against them.”
DJL devotes an entire chapter to threading in Swing. I asked Scott whether he thought threading was a common pitfall for Java Swing developers and therefore was it something inherently wrong with Java’s design:
“Anyone that is a software developer gets paid for a reason. Software development isn’t something that you can master in a three day correspondence course. I’ve always felt that it is each developer’s responsibility to become competent with the features of the language/toolkit they are developing with. Threading is a core part of writing desktop applications. You can easily find discussions about desktop threading on the Internet in regards to numerous other toolkits. It makes no sense to me when people complain about threading in respect to a language. No one complains they have to learn OO to use Java or for-loops to use .NET effectively. In regards to Swing specifically, it is designed very similarly to other common UI toolkits. If you look at QT, GTK, SWT, .NET, etc., you will see they all use some variation on the single event thread concept. Some have the concept of a global lock, however I’d much rather have the ability to address such complexities myself than a brute force approach supplied for me. I will concede that a few more threading utilities built into the core of Swing might help new developers. However, open source projects such as Foxtrot, Spin, and SwingWorker address a large portion of Swing threading related issues. Relating back to my earlier point, I think it is the responsibility of good developers to become aware of the tools that can enhance their development process.”
An interesting point here is that other UI toolkits use this threading model, but you rarely hear that these toolkits are slow. Yet, I have seen examples for most which also block the thread and therefore become unresponsive. I think Java has had some bad luck in that its legacy has stuck. Nowadays though, I do believe that if you see a slow Java application, the fault lies at the developer’s door, and not Java. For example, Eclipse had recently come under fire for becoming slow – especially with its start up. Critics automatically assume that this is because of Java. In its most recent M7 milestone release they significantly improved performance – a bottleneck being the plugin framework that Eclipse relies not being very scalable for increased numbers of plugins. The point being that this is an algorithmic issue – one that could have occurred in any language, yet it seems to become a Java issue. Of course, some more prominent articles and examples covering common pitfalls would certainly help to ensure new UI programmers get good performance from the outset.
Java2D
Some other performance issues have been down to the underlying graphics framework, Java2D. Because Swing components are all emulated, they are very much at the mercy of Java2D. Fortunately, this package is extremely competent in features, and by virtue of being graphics orientated, very quick too (i.e., performance of any graphics framework is a core priority, and Java2D is no different). However, the Java2D have been working hard recently to improve several aspects that should enhance this even further. One area is the use of hardware acceleration where possible. This must be a nightmare to implement in a multi-platform fashion, but it’s being done, slowly but surely. I hate to say it, but Microsoft has made this easier for the Windows platform due to its DirectX graphics abstraction layer. Windows users can expect to see this pipeline utilised even more in future releases. The OpenGL pipeline is also being advanced significantly which will benefit all platforms (currently, support is disabled by default but can be switched on; this will be enabled in the next release.)
There are also a few little tweaks for Mustang that will even help in the “perceived” performance problems. For example, the abolition of the infamous “grey rect” problem. The fix required the use of true double-buffering support for Swing, which is another great boost for the toolkit.
Will someone please think of the users?!
As a Java developer, I will happily sacrifice some memory, and a bit of speed, because the Java platform affords many other benefits. I find myself being productive with Java because of its richness and ease of use. I do benefit from the multi-platform aspect too, because I use Linux to develop yet many of my typical users are on Windows.
However, the argument is that a potential end-user doesn’t care how you made the software, but simply how well it works. If my program becomes unusable due to say, lack of memory, that’s one disappointed user. Are they happy that you’ve sacrificed resources to make your life easier? Well, I’d like to think that such cases are extreme and that actually users will be happier that one uses Java, because I can produce better software with it. I suppose that if I knew in advance that the target machine specification was one where CPU and memory resources were at a premium, then I expect I would consider strongly the alternative technologies. But, much can be done to make your Java code more CPU and memory efficient, but you have to program specifically for that.
Summary
My experience with Java Swing (as a user and a developer) over the past year has been very positive. There was a lot of mud slung at Java in its early days and I reckon that much has stuck. This is in spite of Swing – and Java itself – being faster than ever. There’s no reason that Java applications should be poor performers nowadays… unless you’re low of memory, that is. Memory consumption is still a make-or-break issue, I think. The “memory is cheap” come-back is not very useful in this situation either, and I think Sun knows this and are hoping to continually improve on this issue. Yet, don’t be fooled into thinking that it’s only Java that can suffer from memory issues.
Despite all that’s been discussed, I know that this will not help to change many peoples’ minds. As Lewis and Neumann say “…in web flame wars, people are happy to discuss their speed impressions for many pages without ever referring to actual data.” I’d like to think that those Java critics reading would re-examine the current state of Java, especially with the many enhancements coming in the next release. Joshua Marinacci recently blogged: “When I see an ugly webpage I don’t blame my browser, I blame the site designer.” This can now be applied to Java performance issues, insofar as poorly performing Java programs are due to poorly programmed Java code, and not because it’s a Java program.
Probably the only real way of proving how far Java has come is by demonstation, yet Jasper pointed out:
“Java lacks the great applications that show what is possible; some are getting there like Netbeans or IntelliJ but nothing mass market. Limewire is ok, but you can’t say wow! about it.”
Perhaps this is why the perception of poor performance still exists: think of all the typical everyday apps one uses, such as email client, browser, IM client, media player, etc. There aren’t many Java examples within those categories. I bet within the enterprise, there are lots of bespoke solutions that already show off Swing’s potential – yet we’ll never see them. Many Java developers are aware of Java’s capabilities because many of the best examples are tools for Java developers! I’ve found apps like Intellij – a massive and complex Java IDE – to be blisteringly fast. Java is already good enough for the desktop, but I really believe that Mustang will be a watershed release and we’ll be seeing quick growth of (well written and good performing) Java desktop apps in the next couple of years.
I’d like to thanks Scott Delap, Jasper Potts and Romain Guy for their input and suggestions to this article.
About the author:
Andrew Roberts is a computer science graduate from the University of Leeds, UK. He remained at Leeds to study further towards a PhD in Natural Language Processing. He has been using Linux for almost 8 years, and Java has been his language of choice for advanced language processing and machine learning during the last three years.
If you would like to see your thoughts or experiences with technology published, please consider writing an article for OSNews.
Oh .. and before someone starts the “Buy better hardware” thread :
the slow applications are used on an AMD64 3200+ with 2gb ram, Sata raid 0.
and the same goes for my T43 Laptop with 1.5gb ram.
python/C#/C apps will load almost instant (1-2 sec), java apps still requires 10-20 sec load times.
Personaly I am not a fan of Clear Type and have it off by default. But Java’s font rendering is poor in its non-antialiased form and its antialiased form. Just compare how text in Java/Swing looks compared to Windows, Photoshop, Flash or most apps for that matter. I recently used PHP over java for rendering dynamic images for the web because its font rendering was way ahead. I hope the new Mustang will improve all font handeling not just sub-pixel.
At Xerto we all use IntelliJ, it has so many ways of helping you like refactoring and intentions etc. I think I am probably 20-30% more efficent with IntelliJ then any other IDE I have used. I think Eclipse has copied a lot of the features but I just find the interface hard to live with. We use the IntelliJ gui builder for layout in dialogs and wizards but all the main panel is layed out by hand. This is mainly due to limitations in the IntelliJ gui builder, like you can’t add custom containers, or components that you want to construct you self. It would be nice if you could add place holders which can be replaced with your own component in code. We have started to use the IntelliJ layout manager from code which works well. The reason we like there layout is because it gives you lots of control over the spacing between things, if you ask any designer they will tell you that the white space is just as important as the content in making something look nice.
The thing that strikes me is that most of the comments are from anecdotal experience (including much of mine!) For example, I don’t know what I’ve been doing differently over the years, but I’ve never had to wait long at all for the JVM to load. Up until recently, my PC was an old Athlon 600 with 256MB RAM. On that machine, some Java apps did run slow (like Eclipse), but, so did many other apps written in other languages. So, from my experience, Java hasn’t been that slow, which is why I still use it.
My current machine is a laptop with a Pentium 4M 1.7GHz with 1GB RAM. This is the fastest machine I’ve owned. I friend has new AMD64 at 3+ GHz plus ~1.5Gb RAM (I think) and that runs super-fast. So, my machine is slower than my friends, but it still feels extremely snappy – more than adequate for my needs. It’s slower than the latest specs coming out, but is it “slow”?
Those who complain about the speed of Java applications for desktop should try the backup application AKGBackup (http://www.akgupta.com/applications/akgbackup.htm) and compare its speed with other backup applications. I am sure the experience would prove to be an eye opener.
> Here are a few obervataions:
> – Azureus normally occupies 32mb of ram on my computer, > while firefox normally occupies 40mb (few pages opened)
Ehh, did you (and many others here) just compare a simple P2P-application to a complete web browser?
First a word on java benchmarks. I remeber reading a performance tuning book on java while in the throws of a huge project invovling java, J2EE, Websphere, etc…
The book went on to measure a web server perfroamnce in java and then compare it to some c++ ones. And then showed how to make it compariable via various techniques. What amused me no end, was you had to use dozens of techniques (which are good practise in any language ) to get it perform equivilantly to an unoptimized version of the C++ one. If you applied the same techniques to the C++ one, it would be in the lead again. This sentiment kinds of summirises all I have every heard of java, well you can make it perform well if you code correctly. I am sorry this is true of any language!
As an example, I coded many applications in java, and when they were too slow, I would code them exactly the same in C++. I have done this dozens of times. Most of the time, what you would see is say the java one taking 10 seconds to do XYZ. Then C++ would take 8.5 seconds. No biggie you say ?
Well what if I told you the C++ one used 10-20% of the cpu for those 8 seconds and java used a woping 100% for its whole 10 seconds?
In the end we could only get between 20-40 users onto each cloned JVM for that particular project, ironicallty this was due some of the much vantid caching techique you have to use to get java to perform? while I never did the whole app in c++ (I am not that sad) I have no doubts if we where using other langauges like c++ we could have got far more scalability with the exact same design and hardware.
**”Andy, I don’t like Java because it’s slow” are the very same people who use Perl/Python/PHP***
Speakign as someone who has done extensive work on J2EE business applications as well as B2B java apps etc.. I can point out straight away that python, despite some benchmarks, always lands up being super fast compared with java for real world apps I have written! You can rant about JIT all you want, processor specific code etc.. I have worked with both for years and python outpeforms java with amazing regularity.
If I have to choose a dynamic language, with platform independance I choose python anyday!
***”Programs known to be memory intensive by nature, like scientific applications can in fact be limited by the JVMs conservative usage, and so many developers launch their Java apps with special JVM flags that permit Java to utilise additional memory”***
Its simple fact that JAVA consumes more memory to the same thing. It has nothign, YES NOTHING, to do with it being object orientated. Write the same session caching system with C++, JAVA, and python using the exact same CLASS design etc.. and guess what. JAVA hogs the boat. you mention that java gives you a lot of framework as a base. Right ok, python gives me MORE. I can do more in python in less time than java and the overheads are lower. Not to mention doing something in python doesnt require learning a million obscure framework classes that are unintutive. Its intiutive simple and easy to use. Then again, from a memory perspective C++ is so far ahead of both that the comparison is a joke.
The main selling point for java always lands up being programmer productivity:
***”As a Java developer, I will happily sacrifice some memory, and a bit of speed, because the Java platform affords many other benefits. I find myself being productive with Java because of its richness and ease of use. I do benefit from the multi-platform aspect too, because I use Linux to develop yet many of my typical users are on Windows.”***
And to be fair I can argue this when comapring to C++. The language is cleaner, easier to use. In fact I really liked learning java. However the syntax is not enough to make a language great.
So what about platofrm independance ? well I speak from experience when I say that java is not write once run everywhere. Its write once, test and tweak everywhere.
Its platform independance is far better than that of c++ and other similiar languages. However there are languages which are far better at it than java. Yes I mention python again, but there are many others.
So what about out the box functionaltiy ? Well I covered that already. Java’s framework classes are a mess, they hard to use and harder to learn. Most other “scripting” type lanaguages provide far more in a far more devloepr friendly way than java.
Ultimatly C++ or any native langauge is gona beat java at most things except programmer productivity and possibly bug counts. But if your in the market for somethign higher level than C++, JAVA (or even .NET ) is NOT your only choice! In fact they are bottom of the pile in my opionion.
Java is great concept and brilliant idea, but people always tend support something based on its founding ideas, not its actuall implementation. Java is great idea, the implementation doesnt give the idea justice though.
My thoughts.
I should point out that Python is a language I use regularly too for my research (I do a lot of text processing) It’s a great language and I enjoy programming with it. Never found it faster than Java, but I haven’t done any analysis on it.
It doesn’t have the same breadth though. Yes, the main Python interpreter is available on many more platforms than Sun’s JRE, therefore, you could argue that it’s more portable. Yet, alternative JREs exist which are available on most platforms you care to think of. Whilst it would be nice to be Sun’s offical JVM, you can still reach a wide range of platforms with Java and open implementations.
“As an example, I coded many applications in java, and when they were too slow, I would code them exactly the same in C++. I have done this dozens of times. Most of the time, what you would see is say the java one taking 10 seconds to do XYZ. Then C++ would take 8.5 seconds. No biggie you say ?
Well what if I told you the C++ one used 10-20% of the cpu for those 8 seconds and java used a woping 100% for its whole 10 seconds?”
Well, sounds like IO was bootleneck. Known, and mostly solved issue (see NIO). However, even if that is true, processor is there to be used, isn’t it?
“In the end we could only get between 20-40 users onto each cloned JVM for that particular project”
What the hell were you doing? Cloning JVM’s? Why? 2 Gb RAM limit? IO problem again, maybe?
“So what about platofrm independance ? well I speak from experience when I say that java is not write once run everywhere. Its write once, test and tweak everywhere”
Could be for you, but we have a full blown ERP written in Swing, and It Just Works across MS, Mac, Linux, Solaris. Just a tiny bit of tweaking to look more native on OSX.
“I have worked with both for years and python outpeforms java with amazing regularity”
Hum, I have just about the opposite experience. Could you please do something like jake2 (lwjgl version) in Python to reasure me?
http://www.bytonic.de/html/jake2_webstart_de.html
I dont know if its been mentioned before, but perhaps someone should come up with a JVM chip so that the OS is not burduned with the JVM. We all know hardware is faster than software, so this would be cool.
I have a feeling i heard something about this recently, but i dont know from whom.
http://shootout.alioth.debian.org/benchmark.php?test=all&lang=java&…
It’s interesting to see that the “perfect” program is one that leaves your memory empty and your CPU idle!
Once again, the benchmarks from the above “Java vs c++” link shows relative performance. Say a Java program uses CPU 5x more than C++. So what? That’s what it’s there for! If it’s causing problems with sluggishness, ask yourself why your OS is letting a process thrash your system. I have C++ programs that give an CPU a good going over, but if it’s the only thing my PC is doing, I expect it to take 100% CPU. As soon as I want to do another task, I expect my OS to manage that (and fortunately, Linux is very good at this)
Ask yourself though, how long did it take, and whether the difference in speeds is significant. A 1Ghz CPU means it’s running a 1,000,000,000 cycles *per second*. So, it can do in a second. Like I said, half the speed of light is still very fast, even if it is half as slow!
Those who complain about the speed of Java applications for desktop should try the backup application AKGBackup (http://www.akgupta.com/applications/akgbackup.htm) and compare its speed with other backup applications.
Yeah, like some no-name bloated Java program could beat rsync.
i never thought java was slow on windows, it always seemed fine, even on shitty spec pcs (p2 300, 384mb ram) after seeing the POS that is called a java VM on OS X though, now i know what people whinged about. given the choice i’d never use a java app on OS X again, worthlessly slow
“Once again, the benchmarks from the above “Java vs c++” link shows relative performance. Say a Java program uses CPU 5x more than C++. So what? That’s what it’s there for!”
Wrong. Wrong. Wrong.
Maybe if you were using MSDOS (does ultra portable, write once, run anywhere, JVM run on MSDOS I wonder?) this would be true. However, most of us run *multitasking* operating systems and as such one application hogging the CPU with 100% usage will adversely affect the rest of the system. A more efficient application with 10-20% CPU usage will allow other applications to work happily and the overall system performance will be increased.
So less of this “That’s what it’s there for!”. That sounds like an excuse for Java to be a hog.
***Well, sounds like IO was bootleneck. Known, and mostly solved issue (see NIO).
“””However, even if that is true, processor is there to be used, isn’t it? “”
Well you obviously missed the point about scalability and performance. If it takes twice as much cpu to do something, thats means its processing at half the speed in a multi threaded environment. ( And yes I know half is a lie in real world terms in a bits less but you get the point).
The point is how much can I do with my XYZ box? How many users can I support. How much work a program takes to accoumplish something is VERY relevant. If I can support a 1000 users on XYZ hardware with a C++ application, why would I choose a java one which can only supoprt say 500 ? ( this is just a bullshit example to make a point, no flame wars please)
***What the hell were you doing? Cloning JVM’s? Why? 2 Gb RAM limit? IO problem again, maybe?””””
Cloning is a standard feature of most App servers including web sphere. So to answer your question I will ask you one: Why is it a standard feature of java application servers if you sound shocked anyone would use it?
The reasons being if you give java JVMs too much memory they land up spending more time manageing it than do productive work. Performance tuning websphere (and java vms running there in) is a black art, a balancing act of amzing difficulty. And yes the memory limit is the problem. To support 2000+ concurrent users in a fully interactive data intensive web application with backend ERP integration, telephony, CC autherisations, etc.. all in a call center environment where response times are critical. Java simply cant handle it in single JVM, not even close!
***Could be for you, but we have a full blown ERP written in Swing, and It Just Works across MS, Mac, Linux, Solaris. Just a tiny bit of tweaking to look more native on OSX.**
First off, good for you, second I am not saying Java is useless (JEdit is my favorire text editor), just there are better products. If you have a choise (how often do you really ?), you choose the better product.
With regards portabliltiy, I experienced plenty of issues between NT and AIX (that is it worked differently between the two), they were obscure I’ll admit but its not write once run everywhere. This was 1.3, maybe its better now. I can only speak from what I have personally experienced.
***Hum, I have just about the opposite experience. Could you please do something like jake2 (lwjgl version) in Python to reasure me?
http://www.bytonic.de/html/jake2_webstart_de.html***
Since I dont read the langauge I am not sure what it does. But if you want a specific example, a while back we had to Process a 400 MB CSV File with 30+ columns. We accessed about 20 of the columns using numeric indeces, and wrote them to a new file. In python we used the std CSV class. In java we used a 3rd party class found via google.
I dont recall the specifics, but it was at least a 30 second difference when we did it (python 1.4/Java 1.4 I think). since we needed it run regularly for a while, we opted for the faster.
Well, if intelliJ is “blisteringly fast”, can you tell why the interface is so plain, but still you can see the redraws from top to bottom…
just a simple check: copy something to the windows clipboard.
then click on the “project” button on the left thin “tab bar”. a slide-out pane will open. AFTER it opens, with a considerable delay, the “paste” icon on the top toolbar changes from grey to normal. On this AMD Athlon 3500+ machine with 1GB of memory, this kind of delay is very unnerving. And, YES, from this kind of little things the user experience consists. And, excatly because of no attention to this, everyone sees java as slow and unresponsive. Waiting at least half a second until the icon becomes normal from grey ? Why is that so ? Because the icon bar update is taken care of after something else or what ? You don’t get such behaviour in any NATIVE utility. And if intellij has a bug there that causes that delay, imagine how hard it is to write a good application, if even they cannot do it right.
All in all, it seems that java currently allows creation of bad applications easily, while being very hard to develop responsive applications on.
p.s. other examples from intellij:
on the same pane, there are two buttons, “project” and “packages”. click on any of them and then on the other, on the first one again etc. Play with them. Do you see the icons above them updating ? It’s supposed to be instanteous. it’s not. why ? These are the things which cause user to say an application is “unresponsive”.
never mind that any native menu’s are not available. Like, you don’t always get a chance of right-click “copy/paste” menu in text fields, do you ? That is called consistency.
Also, if we’re talking about the new hardware-accelerated stuff, it only shows that really, there’s no platform-independence (like any mobile developer will explain to you), you always need to tweak your app to the platform it’ll run on.
Let’s continue with the same IntelliJ program.
in the same pane, you can see the pane “title bar” with four buttons on the top. What do they do ? Why aren’t they made in the same style as others ? Why do they only light-up when clicked ? No tooltips ?
oh..
also, please don’t blame people for the java’s bad performance ideas “sticking”. Everyone knows first impression matters. Java blew it.
About the open-source toolkits to “fix” java stuff. Well, why didn’t java include them from the start ? You said for yourself that it was java’s idea to have everything implemented from the start and not depend on open-source fixes, didn’t you ?
Well, it seems that idea was incorrect now.
There is a reason why most of the people think java is bloated. That’s because if you really want to write a nice app, you use 3rd party skins, you use 3rd party memory management mechanisms etc. Why include them in the first place ? To allow people to write bloated apps ? Well, that was accomplished, a complete success. 100% of the apps tried were unresponsive (unresponsive is not slow, it means that you may get the same results only twice slower, but user experience is ten times worse). As you see, nobody wants to write a wrod processor or an email client in Java, and there’s a reason to it. Those applications do not require any much processing power. But they require user experience, and responsiveness. Java clearly lacks at it. And what is going on with no double-buffered display capability ? What century are we in ?
My machine is slower than yours, but Intellij runs and redraws as fast as any native app, in my experience at least. I don’t what I’m doing different. Maybe it’s an OS thing. I’m in Linux and all my Java apps run smoothly as any other app. It’s not that I’m a particularly patient guy. I know what a slow repaint is, and I don’t see it.
But that’s something you need to look at. It’s runs slow for you; it runs fast for me. Based on these experiences, is it slow or fast?
When Windows first came out, it blew. When the next came out, it blew too; And so on and so on. (Some say it still sucks) But, it’s the most popular OS on the planet. Part of its success is obviously from its devious marketing strategies, but it’s also because it gradually improved. First impressions didn’t count here.
The Linux kernel, when it first came out, couldn’t do a lot. Now, it’s running on some of the fastest supercomputers there is. First impressions would have denied this, surely, because when Linux first came out, it wasn’t very good.
Most things when released aren’t up to much, especially commerical offerings, since they need to get products out of the door, even if it’s not fully featured. They get better though.
First impressions are important, but if you want to be taken seriously, you have to judge things on their current merits, because hey, things change!
That article went into religious ranting mode pretty quickly.
As a user, Java is too slow. I don’t really care about the memory issues, just usability and speed.
Azureus on Windows takes too long to start up, and its UI (SWT) is sluggish. The same goes for Eclipse.
On Mac OS X, a platform with excellent Java support, Xcode launches so much faster than Eclipse, it’ll make your head spin. You’ve got projects open before the Eclipse splash screen loads. Xcode + 1 project + 1 source file open is taking up 47MB on my system, Eclipse + 1 project + 1 source file is taking up 69MB.
Sorry, I mentioned that I don’t care about the memory issue. Eclipse is sluggish while working, too. Even if you don’t typically launch/exit your IDE several times a day (with something like Xcode, I can, because it’s not painful), you get these exciting pauses and halts while it loads features on the fly, or just decides to wait a while, or does a garbage collection cycle.
At least you can double-click .jar files these days, or developers provide a platform-specific launcher, so users can ignore the insane java command-line launching.
Every Java project I’ve seen has been written/deployed in Java because it’s “in”; the “free” cross-platform ability of Java has resulted in a lot more work for the developers and the testers, who’ve had to work against platform-specific JVM bugs and behavioural differences.
No sale.
– chrish
I too run a multi-tasking OS. I therefore expect it to make the most efficient use of my resources. Running everything at 20% CPU load is not actually efficient. That’s known as wastage, because you’re super-fast processor is under-utilised. I want my OS to use available processing capacity, yet, if I multi-task, to let me multi-task, and therefore balance the load evenly. This can be done without running tasks at 20%.
IIRC, in Germany, some Autobahns (motorways/freeways) don’t have speed limits. Instead, you are restricted by relative distances between cars. So, you can go as fast as you feel safe to drive, just so long as you don’t get too close to the car in front. That’s the way I want my OS to run, and funnily enough, Linux does that for me.
Could I recommend a quicker IDE? JBuilder is quick, and I’ve personally found Intellij to be as responsive as any IDE – Java or not.
I’ve found Eclipse to be sluggish at times. The current milestone is much better. But, the Eclipse framework is meant for large-scale flexibility. I’m not surprised that it takes a performance hit. Still, it’s my main IDE and find perfectly decent speed wise.
.. optimize for different cpus, yes?
I’m not a C++ guru, but when you compile your generic app, what CPU level to you target for? I guess you have to target for the lowest common arch. Am i right?
With Java, you can run the same code on one two machines and you get a performance increase as one JVM can benefit from the extra features in the CPU.
Can anyone else comment? I saw an article somewhere, but cannot find it.
Anyway, i just downloaded Eclipse SDK 3.1 RC1, and shit it’s fast. The performance increase on Linux is so great that it now performs like a native GTK2 app. That is no mean feat. This IDE is now king (in my opinion). Probably why Borlands new IDE will be based on Eclipse.
—-
daz
The platform independence of java is a SHOULD-BE, not an IS.
If I write a java-app, and I get it working with Internet Explorer on Windows, I would like to be absolutely sure that this application will also work with Mozilla on HPUX.
Fact is, it does not, and it does seldom. If its the fault of Explorer or Mozilla or Java I do not want to know, it is the task of java to make sure that differences of browsers make no difference. The only allowance I would make, would be for java to display a window stating that the current browser is not java-compatible if it is not running.
i went to a page ( http://shootout.alioth.debian.org/benchmark.php ) they are making so-called benchmarks. i picked an algorithm that it seems it has very bad results in java.
Algorithm was “the fasta algorithm” i think related with Gene patterns. Anyway, i copied the test to my machine, indeed it took 170ms to execute it, while the C++ version took 2.45ms.
then i made a quick check on the software. there was one line which is used for printing out the result to the console output (it was creating the output letter by letter thousand time.). i eliminated that line. You want to know the result??
170 micro seconds!! it was A THOUSAND TIMES faster. every java programmer knows that using console output is a very slow process and it is avoided at all costs, that is why people uses logging mechanisms.
i even tried using a StringBuffer for that line, result was 16ms. which is ten times better then the original numbers. if you just do not write it, but write it to a StringBuffer (because writing console output in IDE is a mgnitude slower then the OS console) it was only 3.5ms.
Result-1: that benchmark page is created just for FUD by a dumb ass.
Result-2: Do not believe in micro benchmarks.
Now, you might think the answer to that problem is that you simply need to use more things written in Java. This isn’t quite the case either though since Java applications all JIT their code instead of linking with shareable object code so the OS doesn’t have visibility into the fact that the code is the same and could be shared.
I guess you are not really aware that Hotspot in J2SE 5 is capable of sharing class files between difference instances of JVM. And yes, starting another java app is a lot faster.
The JIT compiling problem can be solved by chaching compiled code into the harddisk and use that instead of recompiling the software with JIT compilers. This means your java app will be a lot faster the next time you start it up.
> run on many platforms straight away without modification ?
What many platforms?
java runs on one platform. The java vm.
Eclipse does a lot more than XCode. It has all sorts going on in the background. Parsing, compiling, etc. This is going to take a hit, no matter what language you use. Let’s face it, Xcode is a very simplistic IDE by today’s standards. There is no code folding, no background compilation, automatic error checking and correction suggestion, the list could go on.
Of course, Eclipse will start slower and may perform more sluggishly. Slow startup is Java’s fault but the slightly sluggish execution is due to all the features Eclipse has.
Java is fast enough for most tasks. I imagine that after 130 posts, everything that needs to be said has already been said.
Then why don’t you contribute your code to the benchmark and stop the FUD?
“Then why don’t you contribute your code to the benchmark and stop the FUD?”
i do not believe in micro benchmarking. but this kind of stupidty should be stopped. i send a detailed message anyway.
Problem here is, that algorithm is actually only measuring “console-output” speed in a stupid way, not the actual algorithm at all.
most algorithms and numbers there are pure bull s*it. When you have a DNA stram of a trillion values and make a patten matching there, now that is an algorithm.
I’m not sure those benchmarks are deliberately spread misinformation. There aren’t many who are experienced in all the languages included to know how to make it fair. If you contact them, I’m sure they’ll consider your amendments.
My problem is, i am against this kind of pages. People are putting micro benchmark results, or line counts as a measure of productivity of a language? those are the most important things unless there is a real bottleneck.
While coding java there can be performance issues depending on your awarness of the language, but in my experience, i have never and ever has a performance problem that could not be fixed in Java. it is low level enough to create a custom solution if the high level solution does not work.
In scripting languages those bottlenecks are far more frequent and usually you cannot find a workaround.
Anyway, if i have time i will check some of the algorithms there just becuase they are spreading wrong information, but note that i do not value those comparisons at all.
“those are the most important things unless there is a real bottleneck. ”
should be
“…are not the most important….”
C/C++ can realy be faster, thats right. But don’t forget, ASM is faster than C++ or even C. I think that discussions about performance will ever come up if a newer technology will be born. This is not a new type of debate. Some peapole like rawness and as fast as possible applications another like even simplification. And we should not forget that java brings some simplifications to allow us to develope faster.
To remember some one, that Java has also examples of possible speed is the Quake derivate called Jake. I know it can be faster, but it is an example of possible speed and like this way to show the possibilities. This example shows me, that java is fast enough for me. Another example is a mass compilant product with a big success is Azureus. It shows that a java application can run fast enough to be used by masses.
So my point of view is: i don’t want go back to ASM.
Java is not that much easier to code in than C++.
So please bite the bullet, read a book, and change your ways.
Writing code using an efficient native code compiler will be the most rewarding experience for you.
Just think you will be using ‘native methods’ all of the time!
And you can use a garbage collector with C++ as well.
Why convert? I use Java, C++ and Python on a regular basis. “Converting” implies exclusivity. I use the right tool for the right job (from my perspective, at least) and I’m sure I’m not the only one.
Java is not that much easier to code in than C++.
I am sure you enjoy throwing exceptions in C++. C++ is also that much more portable compared to Java: You only need a few hundred lines of IFDEF’s! All implementations of C++ are perfect and you can make full use of the STL! And MFC is the most object-oriented API ever!
Writing code using an efficient native code compiler will be the most rewarding experience for you.
Just think you will be using ‘native methods’ all of the time!
And you can use a garbage collector with C++ as well.
I bet you are not aware of GCJ and ExcelsiorJet.
I am sure you enjoy throwing exceptions in C++.
I’m detecting sarcasm, but I don’t get it. How is exception handling that different between C++ and Java? I’ve been out of Java for a couple months, but I haven’t heard of a new exception handling mechanism from the try/catch blocks that handle thrown exceptions.
C++ is also that much more portable compared to Java: You only need a few hundred lines of IFDEF’s!
That’s just flat out bull. There is a C++ standard that all decent compilers understand. If you write according to the standard, there is no reason for #ifdef’s, other than some low-level OS code. And even with that, the only difference between Java and C++ is that Java’s “#ifdef’s” are in the JVM and the appropriate place for the C++ #ifdef’s are in cross-platform libraries that you don’t muck with.
All implementations of C++ are perfect and you can make full use of the STL!
Unfortunately, not all implementations of C++ are perfect, neither are all implementations of the JVM. But with GCC you have a good compiler that supports many platforms ( http://gcc.gnu.org/install/specific.html ), more than the number that have a Sun JVM (MS Windows, Linux, Solaris x86, Solaris Sparc, Mac OS X).
And MFC is the most object-oriented API ever!
Ugh… MFC is a GUI API for MS Windows. It is not cross-platform, and it is not built-in to the C++ language; I fail to see how this is a strike against C++. Use a cross-platform toolkit like Qt, wxWidgets, or GTK. I’ve fallen in love with Qt, it is significantly easier to work with than Swing/AWT and much better for doing any sort of rapid prototyping.
we don’t really need java or .net anymore. There are easier alternatives
[i]”we don’t really need java or .net anymore. There are easier alternatives”[i]
Care to give an example? Please don’t say Python, it’s nice but they are not in the same league. Those are apples and oranges.
Java/.NET etc. aren’t just about speed. They’re about overall cost.
If you’re developing in house enterprice systems and you can produce code 5x faster (for arguments sake) and easier in Java/.Net/VB than C/C++ but it runs 3x slower you’ve two options:
1. Higher 5 C/C++ programmers at £35k each to match productivity
2. Higher 1 Java/.Net/VB programmer at £35k and spend a couple of £k on faster servers/more memory etc.
As a business, trying to make money, what option are you gonna choose?
“we don’t really need java or .net anymore. There are easier alternatives”
Care to give an example? Please don’t say Python, it’s nice but they are not in the same league. Those are apples and oranges.
Whats makes you say that ? Nothing I can do in java cant be done in Python ( or many other languages for that matter. Haskell, Lisp, Ruby, ……. ?) J2EE ? Check out zope ? Clustering ? Maths? …. what ?
I haven’t worked in C#, and I don’t think VB is in the same class as Java or C#.
That said, I’ve found that there is no noticeable difference in productivity when developing in Java/Swing or C++/Qt.
This is, of course, all subjective. It’s based on perspective and depends on the developer’s experience in the languages.
Thanks for your cooperation.
This thread has been closed because of unnecessary flamewar.
Please don’t send any further comment.
There has been a balance between flaming and reasonable discussion in this thread. Please don’t attempt to silence people.
I didn’t believe that somebody could take it seriously.
Come on, use your sense of humour…
Первый нах и неебёт!