View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion 1 - Stephen Ake


A Comparison of Java to C++

How do these languages differ?
Despite having very similar syntax, these two languages behave very differently. In general, C++ grants more freedom to the programmer, giving him/her direct access to memory using pointers and manual garbage collection. As a drawback, the programmer must keep track of many things that Java does implicitly at runtime - for example, keep track of an array's length and make sure that a buffer overflow doesn't happen. Java will throw an exception if the programmer attempts to access protected memory or dereference a null pointer, whereas an equivalent C/C++ program will crash.
Despite the fact that C++ uses more overhead than C, it is a compiled language, and because of that it is much faster than Java's Virtual Machine, which must convert the bytecode into machine code so it can be executed on the local machine. Recently, however, just-in-time compilers (JITs) implemented in the newer JVMs have dramatically improved in performance such that some Java programs are almost as fast as their equivalent C++ programs.

How does that affect people's programming?
For Java users, in an effort to increase the speed of the program, they may violate object-oriented design principles (e.g., reducing number of function calls, or manual inlining). For any programmer, though, the speed and performance issues affect which language they choose to use for a particular program. No one wants to write a Web-based application in C or C++, and no one wants to write a system-level program or device driver in Java. Both languages (C++ and Java) have their own various quirks and workarounds, and they may affect the way people program.

Links to this Page