Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++ vs Java

0 views
Skip to first unread message

Gala

unread,
Sep 26, 2000, 3:00:00 AM9/26/00
to
hi,

Can anyone please tell me what are the advantages that C++/VC++ have over
Java??

thanks

Gary

Ron Ruble

unread,
Sep 26, 2000, 3:00:00 AM9/26/00
to

Gala wrote in message <39d0a508$0$20...@echo-01.iinet.net.au>...

>hi,
>
>Can anyone please tell me what are the advantages that C++/VC++ have over
>Java??


Well, this is really a better question for the advocacy
newsgroups, but...

C++ allows much greater control than Java. Java
bytecode is designed to be platform independent,
which means it isn't possible to perform certain
very low-level operation in Java.

C++, for example, can be used to write device-
drivers for Win32 or Unix. Additionally, someone
writing user-mode code in Win32, for example,
can specify the processor on which a thread should
run, or code for completely different behavior
on Win95 as opposed to Windows 2000, based
on their internal differences.

But in any language comparison, the simple fact is,
each language is going to have strengths, and each
one is going to have weaknesses.

The only accurate answer to 'which language is
better' is 'better for what purpose?'

Petter Hesselberg

unread,
Sep 26, 2000, 3:00:00 AM9/26/00
to
Each language is pretty good, with C++ reigning supreme in anything to do
with systems programming. Java is touted as being cross platform; in the
real world, this is only marginally true -- Virtual Machine implementations
differ, browser versions differ in the programming model they offer the Java
programmer, bugs are different, APIs are different, and so on.

In Java, the declaration and implementation of a class is done once; in C++
you may split them. The Java approach is easier to maintain; the C++
approach lets you hide implementation details.

Java has garbage collection and uses controlled references rather than
pointers. This avoids memory-related errors, including memory leaks,
uninitialized pointers, bogus pointer arithmetic and what have you. Since
such errors can be hard to debug, this is a point in Java's favor.

Java constructors are similar to C++ constructors, but have some syntactical
improvements, such as the ability to invoke other constructors or the
constructor of a superclass.

Java doesn't have destructors. Since memory is garbage collected, you might
think that this doesn't matter, but in my (not very humble) opinion, James
Gosling made a mistake here. The constructor/destructor sandwich is one of
C++'s most elegant features, good for handling access to resources other
than memory: file handles, network connections, database connections, window
handles, GDI objects and so on. (See Bjarne Stroustrup on this subject -->
http://home.online.no/~pethesse/links.html.)

You can provide _some_ destructor-like behavior for Java by implementing a
finalize() method; it is called if and when the garbage collector feels like
it. And, of course, you can provide your own sandwich layers in the form of
open()/close()-type pairs, and thus do manually what C++ does for you.
Except, of course, that your "close" method won't be called during stack
unwinding caused by a thrown exception. :-(

I also miss (in Java) the C preprocessor. Used with care, this is a very
valuable tool, especially for guarding debug and unit test code against
inclusion in release code. (Smart compilers can overcome some, but not all,
of this limitation.)

Java doesn't have const, except for primitive types. A reference to an
object can be const; the object itself can not.

Off the top of my head, these are the major differences between the
languages. No doubt tomes could be written on the subject; I'm not a
language expert and shall refrain. Both languages have strong points; follow
Ron's advice and use whichever language suits your purpose best.

--
Regards,
Petter
http://pethesse.home.online.no/

"Ron Ruble" <raff...@att.net> wrote in message
news:483A5.799$fx6....@bgtnsc05-news.ops.worldnet.att.net...

0 new messages