Welcome!

Java IoT Authors: Pat Romanski, Yeshim Deniz, Elizabeth White, Liz McMillan, Paul Simmons

Related Topics: Java IoT

Java IoT: Article

i-Technology Viewpoint: Why Java Is Not Slow

Correcting Logical Fallacies

Not to directly pick on Peter Bell at all (he’s a very smart guy and I really enjoy his blog, so this is nothing personal at all), I just noticed something he mentioned in a recent comment on a blog entry and felt that it was something I should address in a blog post rather than a comment. Also, writing this entry gives me a good reference point later to send to people when they present the same talking point to me.

Anyhow, here is the comment that Peter made which inspired this blog entry (which in context, is a quip):

"I also have to question why you’d even consider using CF for a performance critical app - even Java is a little sluggish. If you want bare metal performance and think your time is worth less than the cost of a server, go for it and write the darn app in C++!"

I wanted to point out and correct a common fallacy that I see repeated over and over again are statements rooted in comments like “If you need speed, you could convert your Java application to C or C++”. I don’t claim to be a Java expert by any means, but I do think I have a good enough understanding of the Java platform as well as basic operating systems and compiler theory and the like to explain why this is a false argument. The answer is actually more along the lines of “it depends on what you are doing”, and I’ll explain why.

It’s very easy to see where this misconception started – pretty much every software developer or system administrator has encountered a slow Swing/AWT based Java application which took forever to start, and generally seemed pretty sluggish. Not to mention it probably looked terrible. One of the best Java based desktop applications, Eclipse, even takes awhile to start. On the contrary, C++ desktop applications typically start very quickly, and are very responsive to user input. Generally speaking the symptoms of running a Java desktop application match the reality– C++ is almost always faster for short running programs such as desktop applications.

Another common assumption is that it would seem that the JVM itself is an abstraction above machine level code because it acts as an interpreter, and that C/C++ will always be faster because the resulting compiled code is “closer to the hardware” which is also false. In the early days of Java, the JVM did in fact interpret code, but eventually it started using a Just In Time compiler in Java 1.2 to compile the code down to the machine level. Different implementations of the JVM use various JIT compilers, but the Sun JVM uses the HotSpot JIT. Not only are Java programs compiled down to machine specific code, but the longer a program runs, the better it gets optimized.

The HotSpot compiler monitors and analyzes an applications performance over time, and uses adaptive optimization to eliminate bottlenecks in the machine code, known as “hotspots”. It essentially looks for pieces of code that are ran time and time again, and marks them for optimization. Those pieces of code are then recompiled again into machine specific code for performance. This allows for ongoing performance enhancements that you would never get from machine code produced by a C or C++ compiler such as branch prediction hints.

All of these things are not just unfounded theory, there have been several independent studies about this including this one by the University of Southern California.

Java is now nearly equal to (or faster than) C++ on low-level and numeric benchmarks. This should not be surprising: Java is a compiled language (albeit JIT compiled).

This study is several years old now and doesn’t include testing against the many performance enhancements which were made available in the 1.5 JVM, so I’d be interested in seeing an updated study.

That said, Java is probably much faster than you think. One way I’ve seen the Hotspot compiler in action (and you can try at home) is when working on a simple “Hello World” JSP and keeping track of it’s execution time. Typically on the initial run or two, the JSP page is pretty quick, but then after a few calls of the page the Hotspot compiler kicks in and makes it wicked fast so that it’s execution time is effectively nil.

Now that we’ve spoke to the “Java Is Slow” audience, we should cover the answer to the earlier question of “Is Java slower than C/C++?”. This is more of an “it depends” answer. Generally speaking C++ has the advantage in short running applications, and Java is as fast if not faster than C/C++ in long running applications such as servers, web applications, etc. It also might surprise you to know that Java is also very good in real time systems, but that is another blog post of its own.

More Stories By Brandon Harper

Brandon Harper has been programming in ColdFusion since 1998 and also actively writes applications in Python and Java. He is currently a Senior Software Developer at Acxiom where he works on an enterprise service platform which powers their risk mitigation products. Brandon was also a technical editor for Inside ColdFusion MX, and maintains a blog at devnulled.com.

Comments (12) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
semiosys 02/28/07 10:10:10 AM EST

Java can be slow or can be very fast; it all depends on the way you code.
The not so recent paper "Java programming for high-performance numerical computing"
explains why, comparing java with Fortran for numeric code (http://www.research.ibm.com/journal/sj/391/moreira.html )
Bottom line : avoid objets, prefer scalars; avoid multidimentional arrays, prefer monodimensional arrays.

Java is certainly great for both computing and GUI interaction, just have a look
at the visualization community (Infovis, etc), most of people often use Java
to develop their tookit, very demanding in terms of GUI performances (sometimes including openGL).

Garbadge collection may be the difficult point to argue; but try Javolution (www.javolution.org) and
you'll get rid of the infamous garbadge collection slowing down process.

A happy java user.

Marshall Caro 02/14/07 11:07:15 AM EST

Let's try this again:

1. There are NO appreciable performance differences between programs written in Java and C#, and no practical performance differences with C++ and C.

Java and C# compilers produce meta-code which is subsequently recompiled by their respective runtime engines into machine instructions.

C and C++ (and Fortran and Cobol and Pascal and Algol and ...) compile directly to machine code (earlier compilers often produced assembly code which required post compilation processing).

The modern loaders and optimizers are so good now that there just isn't any performance penalty to speak of.

2. So why do apparently smart people still claim "Java is slow!"???

a. Appearances can be deceiving.

b. Your mileage may vary. Program performance is affected by software design and coding. And Java is purpose built to be machine and OS independent. So Java has an additional abstraction layer between it and the native OS for hardware related functions, most particularly screen output (but also I/O).

We build distributed Java applets and applications for the financial industry that perform MUCH better than our competition -- we can service tens of thousands of nodes across the internet in real-time.

When we started our current business most of our end users had Sun workstations. Now it's almost 100% windows. We haven't had to change a line of code to accomodate the changeover.

Ski 02/14/07 10:44:50 AM EST

Since everyone seems to be focused on the desktop (even though the initial article was broader than that), let me add a couple of comments. I just recently wrote a Java Desktop Application - a MP3 Music Jukebox and Manager. It uses a MySQL database to keep track of potentially 1,000,000+ mp3s, with the ability to easily query the database on a number of categories, and also gives you the ability to write raw SQL if needed. I also use a Java framework I wrote some time ago, which includes logging, event management, background threading, instrumentation, database management including pooling, and a dozen other services. The point of all this, is that through the instrumentation (which can be viewed in a browser since the instrumentation is MBean enabled), I can see ACTUAL performance. Startup time of the app, including rendering, averages about 1.2 seconds (and there are about a hundred Components in the app). Event processing is normally measured in the microseconds (e.g. half or less of a millisecond). I can plow through a 50,000 row MySQL database to retrieve songs in about 300 milliseconds. Having used Windows Media Player, and a number of other Jukebox apps, the Java implementation was no slower, and actually appeared faster. Perhaps some of the people complaining about the performance have not written their code in a manner which provides good performance.

Andre van Westreenen 02/14/07 08:32:39 AM EST

Pardon me, I have been coding since 1973, User interfaces are my cup of tea, Java is a pig when it comes to UI, I'd like to refer to the JVM as the JMV "Java Memory Vortex". To even claim that code compiled and linked as native code code be slower than some bloated runtime engine grinding along just to get a single widget change state, is akin to waxing lyrically about the emperor's new wardrobe. As a language it has it's place and that place excludes the desktop, I'll pitch any old 16 bit p-code up against Java for UI and will beat it hands down..

James Chua 02/13/07 08:55:16 PM EST

Nice blog there! Well explained, very informative and most of all you know what you are saying. I didn't know about the purpose of hotspot just till now that I've read your blog!

Gerd 02/13/07 01:04:39 PM EST

while I was aware of what you say about JIT compilation and the performance of my Java code vs. my C++ code, I am still faced with benchmarked throughput figures that differ by wide margins (in ESB type middleware code). Is it the overhead of all the J2EE APIs? If so, then it is the path length from my API call to the metal for these functions, not for single instruction execution.

So if I have CPU intensive calculations the difference would be negligible, but if I interact with the outside world I struggle with the layers of code in the VM? This would tie in with Marshall Caro's comment on screen output. But it can't be just that, because my "middleware" examples don't ever write to the screen.

BTW, I think it would be an excellent suggestion to store the compiled "executable" code for later reuse.

Jeff Chapman 02/13/07 12:48:34 PM EST

Hi Brandon,

It's refreshing to see someone positively linking the words Java and execution speed.

Unfortunately, you've perpetuated the belief that Java desktop applications are inherently inferior. I've heard many a developer tell me that "Java on the desktop is a toy." If you ask these people a few questions, you will find that they use an IDE to code their mission-critical applications. You will also find that their cherished Java IDE is written in, that's correct, Java. So, these developers are using a toy to do their work.

The problem with Java on the desktop is not the JVM. Sun has made many efforts, which you have already identified, to improve performance. The problem is poorly coded Swing applications. The reason those desktop IDEs are so responsive is that they were written by developers who know what they're doing.

The key to creating a responsive Swing application is the proper use of threading in response to user actions. Without using threading, the code executed in response to a user action prevents the underlying graphics code from repainting the screen promptly. The correct approach is to put the code to execute into a runnable instance that will be executed later or concurrently in a separate thread. This allows the method invoked by a user action to return immediately. The Java Tutorial addresses this issue but it doesn't emphasize it in the examples given throughout the tutorial. Inexperienced developers will load up the methods in response to button and menu selections. The result will be an application that appears horribly sluggish and unresponsive.

Ski 02/13/07 10:50:24 AM EST

When talking about most web and business applications, 90% - 95% of the time is spent on non-execution of your code (e.g. database requests, network, file i/o, infrastructure, etc.). So if one language (environment) was even twice as fast as another, so are still talking about only 2.5% - 5% overall. So the better business decision is to write in the language that is easier to develop, maintain and debug.

Marshall Caro 02/13/07 06:49:27 AM EST

Actually, there is a large performance gap between C++ applications (and C#) -- vs Java apps. But the difference is in screen output -- Java applications go through a layer of abstraction (AWT) that native (Windows) C++ and C# programs do not.

Stu Moss 02/13/07 06:23:46 AM EST

I agree entirely once the app is running (or applet). However by far the biggest complaint we experience is not performance once an applet is started but the time it takes to start a sizeable applet (1Mb+). We have observed that most of the time is spent starting the JVM itself and then the initial compilation of an applet. It would be great if Sun engineers could work out a way to cache results of previously compiled and optmized applets (even after closing the JVM). Better still if we could get the JVM start-up times much lower.

ferhad 02/13/07 04:32:59 AM EST

Thanks.Really great article.Java may seem slow but we shouldn't forget the fact that none of the super fast applications written in C or C++ runs on all platforms without changing their codes.However, Java does this.It runs on all OS platforms like Windows, Linux, Mac.

dugu 02/13/07 01:19:32 AM EST

Great article.Specially I like the last part where you have compared with C++.Thanks

@ThingsExpo Stories
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
More and more brands have jumped on the IoT bandwagon. We have an excess of wearables – activity trackers, smartwatches, smart glasses and sneakers, and more that track seemingly endless datapoints. However, most consumers have no idea what “IoT” means. Creating more wearables that track data shouldn't be the aim of brands; delivering meaningful, tangible relevance to their users should be. We're in a period in which the IoT pendulum is still swinging. Initially, it swung toward "smart for smart...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and ...
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
"We are a well-established player in the application life cycle management market and we also have a very strong version control product," stated Flint Brenton, CEO of CollabNet,, in this SYS-CON.tv interview at 18th Cloud Expo at the Javits Center in New York City, NY.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
Most people haven’t heard the word, “gamification,” even though they probably, and perhaps unwittingly, participate in it every day. Gamification is “the process of adding games or game-like elements to something (as a task) so as to encourage participation.” Further, gamification is about bringing game mechanics – rules, constructs, processes, and methods – into the real world in an effort to engage people. In his session at @ThingsExpo, Robert Endo, owner and engagement manager of Intrepid D...
Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abilit...
In his session at Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to maximize project result...