Mailinglist Archive: opensuse-programming (148 mails)

< Previous Next >
Re: [suse-programming-e] Q4 ppl/w both C++ and Java experience
  • From: Jerry Feldman <gaf@xxxxxxx>
  • Date: Wed, 15 Sep 2004 11:05:52 -0400
  • Message-id: <20040915110552.0f045e0d@xxxxxxxxxxx>
Without including the quotes, let me answer a few things.
First, Java is an entirely new language where C++ is specifically a
derivative of C, that includes the power of C. On the same page, C++
also inherits some of the ugly features of C.

There are a few features of C++ that are different from C, but for the
most part, most C programs will compile and run correctly when built
using a C++ compiler. (There are some exceptions). One must also
consider that C++ is a compiler<->linker model where the compiler builds
a relocatable binary module. The C++ standard does not define how the
linker works, but does describe the linkages. Java, on the other hand is
designed as an interpretive model where the compiler generates well
defined intermediate code (eg. the byte codes) that may be interpreted
on every platform that supports the JVM (or JIT). There are also
features that were designed into Java that are not part of the C++
language specification such as:
Threads. I consider this a plus for Java since the programmer
does not need to consider different threading models.

Graphics. This is a debatable issue.

Some other things I personally prefer in Java over C++:
primitive type standards, such as integer sizes. These are all defined
by the Java specification so that you are guaranteed an int is 32 bits,
a long is 64 bits. In C and C++, an int may be as small as 16 bits and
as large as a long (although most 64 bit implementations use a 32 bit
int). Longs on a 32 bit system are normally 32 bit and 64 bits on a 64
bit system, and could be 128 bits on a 128 bit system.
Character data types in Java are full unicode where they are simply a
very short int (eg. 8 bits) in C and C++.

Another debatable issues is inheritance. Java uses a single inheritance
model where C++ uses multiple inheritance.

C++ also supports templates. Templates are very powerful, and allow C++
to use a single container model to contain just about anything. But,
there are ways to do similar types of things in Java.


Java import vs. C++ preprocessor

These are difficult to compare because they do different things. The
import statement in Java not only serves a similar purpose to the C++
#include, but also it serves as the linker specification as to which
libraries are to be used.
The #include files essentially provide feature codes, function
prototypes, constants, declarations of variables defined elsewhere, and
template and class definitions. But, the preprocessor also contains
conditional compilation features. While the portability of Java may
mitigate this, the conditional compilation in C++ allows for an
implementation to comply with different standards and different platform
dependent features. In a complex product, I generally use this to add
debugging code that I do not want in production code.


Performance:
In most cases, a C++ application will significantly outperform a Java
application. However, some C++ features make optimization very difficult
where a good Java compiler with a good JIT can cause a Java application
to perform well.

There are many IDEs that make both C++ and Java reasonably easy to use
in a graphical environment, simplifying the code.
< Previous Next >
Follow Ups
References