473,889 Members | 1,444 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 21637

Roedy Green skrev:
On Thu, 27 Apr 2006 21:37:37 GMT, "Oliver Wong" <ow***@castorte ch.com>
wrote, quoted or indirectly quoted someone who said :
So how about instead of characterizing a language as being universally
hard or universally bad, we just accept that some people find it difficult
to program in C++, and so C++ is not the language for them? Similarly, maybe
some people find it difficult to program in Java, and so Java is not the
language for those people.
I would be happy with that if people making the comments had working
knowledge of both before pontificating. It seem the people with the
strongest opinions have experience in primarily one language. We are
hearing the breast beatings similar to those about the best hockey or
basketball team, rather than a dispassionate comparison of features.

It further seems these fights could be turned into contests where
teams use their favoured language. The idea is to do the work in the
fewest man hours and have the fastest least resource hungry result.
You would also have a maintainability challenge, X hours to change the
program to do something different. You could get some hard data to

The one I know with expertise in both systems - James Kanze - believes
C++ to be the best and fastest language for software development. But
then he has very high standards for his software.

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

Apr 27 '06 #101
On 27 Apr 2006 15:24:59 -0700, "Noah Roberts" <ro**********@g mail.com>
wrote, quoted or indirectly quoted someone who said :
Hey, my CPU will run C++ byte code natively but there are no CPU's that
run Java source code...guess Java sucks then.

There are machines that run Java bytes codes directly. But even such
machines have some microcode or other assembler assists to handle the
lowest levels. see http://mindprod.com/jgloss/picojava.html

There is no equivalent to byte code in C++ that you as programmer see,
though there may be an intermediate triple form internal to the
compiler using during optimisation. In C++ you compile straight to
platform machine code. In Java you compile to a virtual machine, as
sort of idealized Java CPU similar to a FORTH stack machine. From
then it can be interpreted, JITed, HotSpotted, statically compiled
etc. Code is usually distributed in byte code format, often called
class file format or jars. The byte code format is
platform-independent. The platform independencies are handled by a
platform-specific JVM (a program written usually in C++) and set of
standard class libraries.

See http://mindprod.com/jgloss/compiler.html
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Apr 27 '06 #102
In article <11************ *********@g10g2 000cwb.googlegr oups.com>,
peter koch <pe************ ***@gmail.com> wrote:

Large parts of the C++ libraries are implemented in C++.

This is also the case with Java. Even the Java compiler is implemented
in Java.
Interestingly, of course, while there are no CPUs that support C++
instructions natively (that I know of anyway), there are those that
support Java bytecode natively. The conclusion being that while it is
possible to have a pure Java system, it is not possible to have a pure
C++ system :-)

I do not understand that one - are you trying to put a joke on me - or
do you propose that Java should run only on processors supporting
byte-code? ;-)

It's just an observation. Since Java always compiles to one specific
instruction set that can be implemented in hardware with relative
ease, it doesn't need to rely on non-Java components at all.

You could still make it perform differently on different platforms but
I am not sure why that is important at all.

Bent D
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
Apr 27 '06 #103
On 27 Apr 2006 12:31:12 -0700, "peter koch"
<pe************ ***@gmail.com> wrote, quoted or indirectly quoted
someone who said :
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!

come on. There are alternate notations that generate the same
assembler code. That is a legacy wart, not a feature.
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Apr 27 '06 #104
In article <11************ **********@v46g 2000cwv.googleg roups.com>,
peter koch <pe************ ***@gmail.com> wrote:

This is playing wordgames. I don't care if it is what is in Java-speak
called a memory leak or pack-ratting. The fact is that you have to do
some "resource management" stuff to avoid memory usage increasing ad
infinitum. And this is not theoretical. If I remember correctly this
behaviour was found in a released official Java-library.
Swing is rather notorious for this. If you don't remember to call
"dispose()" on your GUI windows when you are done with them, they may
decide to stick around indefinately. This then also prevents the GC
from collecting everything that is referenced within the window, which
can be a lot.
So Java is not
just "allocate and forget" even when it comes down to "pure" memory.
Again the advantage is with C++.

Depends a bit on what you mean by "pure" memory, but that is probably
too academic a debate to get into.

Bent D
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
Apr 27 '06 #105

Roedy Green wrote:
On 27 Apr 2006 15:24:59 -0700, "Noah Roberts" <ro**********@g mail.com>
wrote, quoted or indirectly quoted someone who said :
Hey, my CPU will run C++ byte code natively but there are no CPU's that
run Java source code...guess Java sucks then.

There are machines that run Java bytes codes directly. But even such
machines have some microcode or other assembler assists to handle the
lowest levels. see http://mindprod.com/jgloss/picojava.html

[blah blah blah JVM blah blah]

I know all about that. Point is that it was asserted that C++ is not
as good as Java because Java binary code will run on some processors
but C++ source code won't. This is just stupid...almost as stupid as
me having to point this out to you.

I definately hear a vacuum...

Apr 27 '06 #106
On Thu, 27 Apr 2006 22:48:59 +0100, Andrew McDonagh <ne**@andmc.com >
wrote, quoted or indirectly quoted someone who said :
go Ruby ..Go Ruby...Go Ruby

“I always knew one day Smalltalk would replace Java. I just didn’t know
it would be called Ruby." -- Kent Beck

My ex boss, (one of the cleverest guys I have ever run into) has gone
gung ho on Ruby. I did some work documenting it. It has much of the
appeal of Python, not making you ramble on for pages telling the
compiler things it can figure out on its own, but on the other hand,
it seems a lot harder to figure out what a program is doing without
all the embedded type clues.

I wonder if someday we will have a language that lets you write like
Ruby, but that does all kinds of inferencing to tell you additional
info like types, potential bounds etc. but only when you want to see

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Apr 27 '06 #107
On Thu, 27 Apr 2006 20:42:21 +0000 (UTC), bc*@pvv.ntnu.no (Bent C
Dalager) wrote, quoted or indirectly quoted someone who said :
Java-based CPUs for desktops have been tried I think, but it didn't
take off.

they ran too hot.

But there are all kinds of tiny CPUs that run JVM byte code directly
(or more precisely in microcode).

This approach saves a lot of RAM. You don't need room for a JIT,
machine code, JITED machine code etc. All you have is nice compact
byte code.
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Apr 27 '06 #108

On 27 Apr 2006 12:45:27 -0700, "peter koch"
<pe************ ***@gmail.com> wrote, quoted or indirectly quoted
someone who said :

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

Have you read the book? Were in there on BIX when Stroustrup dropped
by for a month or two?
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Apr 27 '06 #109
peter koch <pe************ ***@gmail.com> wrote:
There are two questions being considered simultaneously here. One is
what is required to produce useful software in a language. The other
matter is what is required to understand that language. I side with the
position that a language that's hard to understand has a weakness in
this even if it remains possible to write software using that language.
I agree here. Readability matters a lot. And here C++ is a clear
winner, due to its more advanced features such as templates, operator
overloading and RAII,

You seem to have missed the point... whether intentionally or otherwise,
I don't know. I am referring to how quickly the language can be
understood; not how quickly software written in the language can be

Nevertheless, since we're now talking about it:
// C++
class_with_poss ible_ressource cwpr;
dosomethingwith (cwpr);
// Java

void func()
ClassWithPossib leResource cwpr = new ClassWithPossib leResource();

doSomethingWith (cwpr);

I don't know where you got the so-called Java code you posted. Whoever
gave it to you, don't accept their Java code any longer. Corrections
aside from syntax and naming conventions include:

1. A constructor would throw an exception if initialization failed, so
there is no need to check for that situation.

2. There is no need to catch exceptions within the finally block. If
the call to the clean-up method (e.g., dispose) fails, then an exception
will be thrown, which is what you wanted anyway. Although some people
may choose to be picky about which of the two exceptions they wish to
see in case doSomethingWith also failed, the C++ code doesn't handle
that any better, so it's rather irrelevant here.

3. Removed the cast to an interface before calling dispose. Upcasting
of references is always dispensible in situations like this. It appears
to have been added for no other reason than to make the Java code look
longer and uglier. Actually, come to think of it, most of the code that
was posted appears to have been added for that reason.
Four simple lines of C++ becomes 21 lines of complex and convoluted
Not sure how you're counting. Nevertheless, the C++ code is clearly a
little bit shorter, since the Java code needs to make cleanup explicit.
So the Java func above is as easy to understand as the C++-one?? Come
on - you do not really mean that.
No I don't mean that. See above.
Also you have a huge problem writing
generic code in Java .... those ugly and presumably costly runtime
checks have to be made all the time.

How is that relevant? Or is this just becoming a gripe list about
languages, which you obviously don't understand to begin with?

The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Apr 28 '06 #110

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: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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: 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: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.