473,889 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On Java and C++

Java programmers seem to always be whining about how confusing and
overly complex C++ appears to them. I would like to introduce an
explanation for this. Is it possible that Java programmers simply
aren't smart enough to understand C++?

This is not merely a whimsical hypothesis. Given my experience with
Java programmers --- the code they write and the conversations they
have --- Occam's Razor points to this explanation. For example,

"Oooh I'm confused about the difference between pointers, references,
and objects! How confusing!"

"Oooh operator overloading confuses me! The expression x + y is so
confusing, who knows what's happening with that? If x and y are
complex numbers, what the hell could x + y mean?"

"Oooh multiple inheritance is so confusing! Though I am both a father
and a programmer, I still find it so confusing how the same object can
be two different things! How confusing!"

"Oooh and virtual bases are so bizarre! I am a student --- myself
'the father' is the same student as myself 'the programmer' --- but
nonetheless the idea of virtual bases is absolutely confounding and
confusing to me!"

Again, Occam's Razor is a valuable tool here. In deciding among
competing hypotheses, choose the simplest one. To impartial observers
of indoctrinated Java programmers, the explanation is simple indeed.

Apr 26 '06
458 21629

Remon van Vliet wrote:
"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** **************@ t31g2000cwb.goo glegroups.com.. .

There are also the three exception guarantees, which are applicable in
ANY language, that also make exception handling in C++ less risky.

If you aren't capable of avoiding a memory leak in an exceptional
situation then you can't handle any other kind of leak and believe
me...the problem exists in ANY language that has exceptions as there
are numerous resources that you gather and have to release that are not
memory related and so you can't use GC as a crutch for that.

It's quite tricky to be really condecending and really wrong at the same
time but hey, somehow you managed. Rather than question the intelligence and
expertise of someone who offered perfectly valid points you may want to
consider either actually having a look at Java instead of browing Java
newsgroups ready to jump in on the first sigh of a troll. I'd be more than
interested in even a single practical example of these resource/exception
issues of Java you speak of that are so much easier in C++...just one..

Well since you can't read and/or comprehend what you are reading I
think it would be a waste of time and effort to offer any proof of
anything to you...besides being unwilling to prove something I didn't
bring up.

Why do I question your ability to comprehend the written word? Because
I _never_ said anything was easier in C++ than Java or the other way
around. The one thing I did say that could even REMOTELY be considered
such was to say that RAII won't work and I already gave the reason why
- you can't depend on the timing of deallocation in Java and you have 0
control over it.

I am more capable in C++ but that is because I rarely use Java. On the
other hand, I am fully capable of coding in Java and have done so many

Apr 27 '06 #51

Remon van Vliet wrote:
What point am i missing if i mention the "finally" block in Java?

That nobody said it was impossible to release resources correctly in
exceptional situations in Java.

What was said is that memory management and exceptions are "mind
boggling" issues and I made the point that you better be able to handle
such things because the problem comes up in any language that has
exceptions as there are other resources besides memory that need
correct handling in exceptional situations. I also gave two examples
of how C++ programmers deal with the problem from the ground up.

Also, you could read that article above which shows some shortcommings
of both RAII and finally. However, the "scope guard" appears to be a D
language particular construct so is rather moot in this discussion. It
is just another way to do the same thing...better or not, I pretend to

Apr 27 '06 #52

Remon van Vliet skrev:
"Alf P. Steinbach" <al***@start.no > wrote in message
news:4b******** *****@individua l.net...
* Remon van Vliet -> Noah Roberts
I'd be more than
interested in even a single practical example of these resource/exception
issues of Java you speak of that are so much easier in C++...just one..

All external resources.

I think this is factually untrue. So, a practical example please?

Just one simple example, then: files. The lack of cleaning up of
resources in Java is so common that the Java library calls the
garbagecollecto r whenever opening a file fails. Often this solves the
problem since the likely reason is that the program leaks this
You might argue that there's a solution to that problem, but the
"solution" is a hack and it works less than well on a system that is
truly multiuser.


People who come from e.g. Java or C tend to not see those issues as
problems, because in those languages there's just no hope of dealing
preventively with fundamental resource leak issues, so the pragmatic
approach of "if it becomes a real problem, let's deal with that concrete
real problem" is applied instead of designing in any guarantee from the
start. Pick up any C or Java code dealing with external resources of any
kind, and more often than not, there's a potential resource leak staring
the C++ programmer in the eye.

Perhaps said C++ programmer just isnt overly familiar with Java. It seems to
be the red line through these kind of threads.

Look at any reasonably sized Java program and look at the try ...
finally constructs. Likely each of these is a place where resources are
to be released. This is evidence that this handling of leaks is a
manual process which makes the program more fragile. Also it causes the
programs to be difficult to maintain. What happens - as an example - to
However, the C++ programmer would be wrong to chastise the C or Java
programmer for that, because most probably the resource leaks will be
consequences of the intentional pragmatic approach to dealing with the
languages' shortcomings: those potential leaks won't, in general, be actual
problematic leaks.

Add to that that C++ is so infernally huge and complex, like COBOL or
PL/1, that it's seldom used correctly by the average programmer.

Once again this sounds like a C++ developer with a superiority complex.
"Average programmers" here and there. Fact remains i still need to hear of a
external resource leak problem that's consistently easier to deal with in
C++ compared to Java.

I do not understand you. So long as you encapsulate all resources in a
class, there is no chance of leaks anymore. This is not the case for
And in sum that means that the C or Java code may actually have less
relevant resource leaks than the equivalent average programmer's C++ code.
Only for the critical support code written by an expert or experts does
C++ shine. Because there the potential can be realized.

"Critical support code"? like?

I believe most large system out there in the real world relies on C or
C++. Examples are numerous, but I could mention banking,
telecommunicati on and database management systems. I doubt you will
find any large product of this type in Java. There will be lots of Java
in the "supporting " infrastructure of course - most likely my
homebanking solution is Java. But all the "real" and "heavy" stuff is
most likely C/C++.


Apr 27 '06 #53

Remon van Vliet wrote:
You do think one is better than the other,

You need to have your mind reading ability rechecked. It isn't working
anymore. IMHO you shouldn't have grown to depend on it anyway.

Your logical reasoning circuitry could use some work too...

Just some helpful hints.

Apr 27 '06 #54
* Remon van Vliet:
"Alf P. Steinbach" <al***@start.no > wrote in message
news:4b******** *****@individua l.net...
* Remon van Vliet -> Noah Roberts
I'd be more than
interested in even a single practical example of these resource/exception
issues of Java you speak of that are so much easier in C++...just one.. All external resources.

I think this is factually untrue. So, a practical example please?

Perhaps the most infamous was the earliest versions of the Swing library
in Java.

isnt overly familiar with Java
superiority complex.
Fact remains i still need
Keep to the technical, not the emotional, please, even in a trolling thread.

"Critical support code"? like?

That's an ungood question, from the perspective of topicality. What's
critical generally depends on the context (e.g. project, organization),
and describing such a context fully, so that a troller can't take issue
with it, isn't possible in a Usenet posting. However, the C++ standard
library is one example of support code that's critical in any context.

A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 27 '06 #55

peter koch wrote:
I believe most large system out there in the real world relies on C or
C++. Examples are numerous, but I could mention banking,
telecommunicati on and database management systems. I doubt you will
find any large product of this type in Java. There will be lots of Java
in the "supporting " infrastructure of course - most likely my
homebanking solution is Java. But all the "real" and "heavy" stuff is
most likely C/C++.

Oh I think there are plenty of large projects using Java even if I
can't think of one off the top of my head. Besides, any fact that lots
of large stuff uses C or C++ can be written of as a legacy issue
anyway. Millions and millions of lines of code don't get turned over
to a different language just because it's better (assuming for the
moment that Java is 'better') even if there has been over 10 years to
do so. It just doesn't happen and anyone insisting that it should is
going to be out of work really fast.

Apr 27 '06 #56

Roedy Green skrev:
On Thu, 27 Apr 2006 10:43:36 GMT, Mishagam <no*****@provid er.com>
wrote, quoted or indirectly quoted someone who said :
a) You don't have to think should you include fields of have variables
as objects or references or pointers. It is decided for you usually
close to optimal way (closest to references).
This is a huge benefit. There are so many addressing modes in C++ that
really don't buy you much other than confusion.

This is ridiculous - like claiming you only know to drive a car with
automatic shifts because manual shifts are all to difficult. I do not
know what gear to use!

The other huge benefit is platform independence. Java has everything
removed that would temp you to write platform dependent code.
The problem here is that Java is not as portable as C/C++. Also, there
are lots of platforms out there where Java simply can't run.
Granted I tend to use a very vanilla style of coding, but platform
specific problems just don't happen to me.

Even writing something as UI-free as a compiler takes a huge amount of
platform-adjusting application code. In Java, that his already
handled by standard libraries.
Well... the company I work for also programs (partially) in Java and it
has had lots of portability problems. The Java library (e.g. for
locking of files or creating new processes) simply does not work the
same way when moving between Solaris, Windows and AIX.
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.


Apr 27 '06 #57

Roedy Green skrev:

Stroustrup wrote a book about his trials designing C++ called the
Design and Evolution of C++ with a sprouting oak tree on the cover. He
was heavily constrained by his committee of C users who insisted on
strict upward compatibility. The language was designed and implemented
a bit at a time. He was never permitted to have a reintegration/tidy
up phase.

I felt much better about C++ knowing at Stroustrup was on my side in
wanting a cleaner language. It was just he was not forceful enough to
persuade his committee of bosses focused on the current job (which was
not designing a new language) of the need.
That is simply false - and most probably a bloody lie. About on par
with the other posts I've seen from you. Others might want to have a
look at


I think of computer languages as like species of dinosaur. Each new
species can build on the last and do one new "trick". It would be
silly to expect one early dinosaur to be the ultimate. Because others
built on the shoulders of its design does not detract from the
"pioneering " work of the earlier species.
But Java was never meant to be a step forward in the evolutionary
chain. It was meant to be simpler and with less capability than C++,
and for that it sacrificed some safety features present in C++ (such as
e.g. const and ability to pass by value) while removing others (such as
pointer manipulators).
People like to pretend their current favourite is the end point in
language evolution. Getting too attached just slows evolution. We
have a long way to go.

We will have to give up more and more fine control, and let more and
more programming be handled by the augmented equivalent of CSS style
sheets. We will have to get used to the idea of specifying the
desired results and letting computers figure out the best algorithms.
We are a long way from that. But if you focus simply on
high-performance, easy-to-use products C++ has come a long way
delivering this.

/Peter --
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Apr 27 '06 #58
In comp.lang.java. advocacy, Remon van Vliet
<re***@exmachin a.nl>
on Thu, 27 Apr 2006 20:40:42 +0200
<44************ ***********@new s.xs4all.nl>:

"Martin Vejnár" <av****@volny.c z> wrote in message
news:e2******** **@ns.felk.cvut .cz...
The Ghost In The Machine wrote:
[5] Java doesn't have explicit deletes. The garbage
collection is expected to take care of things. (There are
some exceptions; a FileOutputStrea m for example will be
left open indefinitely, even if the reference is lost.)

For some reason, you've put the most important statement in parentheses.
RAII is one of the two reasons I stick with C++. I don't know of any other
language that would support such concept. (C# and D both support RAII, but
require the programmer to explicitly mark objects that should be destroyed
when leaving scope. Why?) How do you do RAII in Java?


Have you ever used Java and actually ran into an issue that requires RAII?


"Resource Acquisition Is Initialisation"


[begin excerpt]

Which Languages are Appropriate for RAII

Or rather, which languages is RAII appropriate for. As will soon be
explained RAII depends on the way that constructors and, in
particular, destructors, get called and the predictability of this

RAII can be used with:

* Languages which can have user-defined types allocated on the
stack (automatic objects in C/C++ terminology) and cleaned up
during normal stack cleanup (whether because of a function
returning, or an exception being thrown). E.g. C++.
* Languages which have reference-counted garbage collection
and hence predictable cleanup of an object for which there
is only one reference. E.g. VB6

RAII cannot generally be used with languages that clean up
objects using an unpredictable garbage collection, such as
Java (however see the Postscript on .NET). If a language
guarantees cleanup of all objects before an application
shuts down then it may be applicable to some problems.

[end excerpt]

I am not certain whether an Object variable going out of scope
in Java is subject to automatic cleanup or not, and if it is,
under what circumstances. Obviously it cannot be cleaned up
if the Object is placed into a Map or Collection. Otherwise,
I don't know.

In Java one can use a try{}catch{}fin ally{} pattern to
emulate RAII, but it has to be explicitly programmed.
One can also attempt overload of the finalize() method,
but the problem is that one has no idea exactly when
that will be called -- if at all. Some patterns (Swing)
implement a dispose() method as well, which Java does *not*
support directly.

#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
Apr 27 '06 #59
In comp.lang.java. advocacy, Noah Roberts
<ro**********@g mail.com>
on 27 Apr 2006 10:59:36 -0700
<11************ ********@u72g20 00cwu.googlegro ups.com>:

Roedy Green wrote:
The other huge benefit is platform independence. Java has everything
removed that would temp you to write platform dependent code.

Well, that is one area where Java *can't* be used then isn't it.

Another can't. Where is the can?

JNI allows for Java to call down to native code. It tends
to be slow and little-used.

That removes the "can't", but replaces it with a "won't".
Other solutions are also possible, such as named pipes,
sockets, and pseudoterminals .

#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
Apr 27 '06 #60

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to connect to the DB I get the following exception at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2120)
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it says: usage: java fit.FitServer host port socketTicket -v verbose I think this is because I do not understand the jython mechanism for inheritance (yet).
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)) and in both cases, get the following list returned from calling getDeclaredFields() on java.lang.ClassLoader via this code snippet: Field fields = loaderClass.getDeclaredFields(); for (int i = 0; i <...
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in Linux there is an error. The code that fails is the following: SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); I´m sure that code is ok. In fact, I´ve found that in several...
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.