C++ versus Java - Embedded.com

C++ versus Java

Although I've been a C++ professional for 18 years, I recently facedthe task of leading a team that had to build a large J2EE Web 2.0application.

Of course, I've always been open minded towards Java — especiallyJ2EE — and using the JBoss application server solved a lot of the workfor free. But as the project proceeded, I saw that we didn't have fewerproblems, just different ones.

Why Java

Java is successfull for two reasons:

  • Java's portability.
  • Java's “idiot-proofness” (at least compared to C++).

Java comes with 100-percent portable libraries, including (as doesC++) I/O, threads, and the like. Moreover, Java supports portable GUIsand more, and the language syntax is adopted from C++.

The main differences between Java and C++ are Java's lack ofpointers and its garbage collector.

The downside is the introduction of a third-party — the JavaVirtual Machine (JVM) — between your program and the operating system.This sounds good if you're planning on a simple application or if youneed GUI portability. But it also introduces new problems, especiallyif you haven't installed the “right” JVM version, or haven't installeda JVM at all.

Why JEE?

JEE, formerly known as “J2EE,” offers services implemented in theJava language and runtime model. At the heart of JEE is an applicationserver (or “servlet container”) which takes care of redundant andstandardized tasks that most server applications use — sessionhandling, persistence (which means database access), concurrency, andthe like. This is good, of course, because once you've learned how touse the application server you can focus on the application.Additionally, standardized tasks in commonly available applicationservers should be more stable, and probably more flexible, than customones.

But there is a price you pay for all this. The more tasks you handover to an externally supplied engine, the more difficulties emergewhen solving problems. This might be okay if your application server iswell supported and maintained, but such engines are often too large totrace down and resolve bugs on your own.

Moreover, application servers are often used in environments thathave lots of users, generating heavy loads. Why use a computing andmemory-intensive platform such as JEE for that?

Why C++?

C++ evolved from C. It is thin and deliveres high performance. It'smore like a set of highly efficient (but sometimes dangerous) tools. Ifyou know how to use it, you'll stay with it. If not, you'll be lostsooner than you might be with Java. In C++, you have to code much moreby yourself than you do with JEE. Additionally, I've yet to find suchthings as application servers in C++, nor have I found many toolkits orlibraries that would help build Web applications. (I wonder why?)

However, comparing C++ to JEE is somewhat unfair because you'rereally comparing a language to a complex server engine and runtimeenvironment. Still though, we talk about two different paradigms thatusually exclude each other and that do compete. But if you arecomparing C++ to JEE, specifically in terms of Web or serverapplications, issues come up that didn't seem obvious to me before.
(Click here to read more)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.