Differences between C++ and Java

O

Oliver Wong

Roedy Green said:
Then you too should drop out of computer science and take up the art
of twisting the truth for profit, namely corporate law. Both of you
are just playing silly word games.

http://mindprod.com/jgloss/newsgroups.html#GIFTHORSE

My intent was to provide some constructive criticism. I apologize if I
was too subtle in my efforts. Here's the sequence of events, and the
rational for my actions from my perspective:

You wrote an essay about the difference between C++ and Java.
Pep pointed out some problems with the statement "Java is platform
independent".
You dismissed Pep's point.
I agree with the Pep's point, and wanted to indicate that he was not the
only person to feel that the statement has some problems, which leads to the
possibility that other people may feel the same way too, but chose not to
post about it.
I (subtly?) ended my post with the advice of "consider your audience".
This is difficult in your (Roedy's) case, because the MindProd site is
oriented towards people with a technical background in Java, but to the
"newbie" segment of that population, so it is somewhat of a grey area
whether the essay should strive for technical correctness versus ease of
understanding. If I were faced with the same problem, I'd give the "easy to
understand" explanation first, with notes that there may be some technical
problems with it, and a link (perhaps as a footnote) to the more complex,
but technically correct answer.

In the end, it's your site, and your essay, so you can write whatever
you want. I had (perhaps incorrectly) assumed you were looking for some
feedback.

- Oliver
 
R

Roedy Green

I'm not sure about the truth-value of your assertion here, as it depends
on how you define a lot of things. Would you consider a Java program in
which the keyword "native" never appears to be a 100% pure Java program?

I am getting really impatient with you. Please google "100% pure java"
so that you know what the term means first.
 
R

Roedy Green

The counter argument to this is that the JVM is not qualitatively
different from a traditional emulator. You could write an emulator such that
C++ programs written for Unix run on Windows (see Cygwin) and vice versa
(see Wine). Does this mean that C++ is also platform independent? Like I
said in my previous post, I don't think it's useful to say a *LANGUAGE* is
platform independent, because emulators, compilers or virtual machines could
be constructed for any language/platform pair.

You just jerking my chain.
 
R

Roedy Green

Would you consider a Java program in
which the keyword "native" never appears to be a 100% pure Java program?

There is on such thing as a Java program that uses no native methods.
The core methods of Java are necessarily native methods. That is not
what 100% pure java means.
 
Z

zero

I was quite surprised when I found out about this, and I wonder
what the
implications of it are when writing C++ code.

It drives you nuts. In addition to that there are multiple ways of
specifying the same thing.

You need various addressing operators including . -> * [] &

On the other hand, it can help make sure you *know* you're handling
pointers/references. Many a new Java programmer (including me) has been
surprised when trying to create a copy of an object and later changing that
copy, only to see unexpected results because they are in fact changing the
original - or some member of the original that was a reference to an
object.
 
Z

zero

Java does not use a preprocessor. C++ makes extensive use of a macro
preprocessor.

It should be said that C++ gurus say "the preprocessor is evil" (with
nuances of course). Very much simplified, the consensus is that the
preprocessor is a remnant from the C days, and should be avoided in C++
(replacing macros for example with inline methods)
 
O

Oliver Wong

Roedy Green said:
I am getting really impatient with you. Please google "100% pure java"
so that you know what the term means first.

Okay, I did as you asked, and I was surprised to find out that "100%
Pure Java" is actually a standardized term from Sun. If you knew this,
Roedy, you could have just said so right away. =P

But it also looks like the term has fell into disuse by Sun. I could not
find any reference to it on the main site, though I did find this PDF on
Sun's archives entitled "Guidelines for achieving the 100% Pure Java
Standard".

http://java.sun.com/products/archive/100percent/4.1.1/100PercentPureJavaCookbook-4_1_1.pdf

The definition of what is and what isn't "100% Pure Java" sure is long!
The PDF itself is 61 pages. Here are some choice quotes to illustrate how
difficult it is to define this term:

<quote>
The purpose of the purity standard is to provide reasonable and economic
assurance that the 100% Pure Java program design guidelines have been
followed, and that the program will run on any Java Compatible platform. The
process is not intended to be immune to subversion, but is intended to be a
chance for you to provide evidence of the portability of your product in a
uniform and consistent way.
</quote>

In other words, there isn't a hard and fast rule as to what is 100% Pure
Java and what isn't.

<quote>
There is a critical distinction-and connection-between portability and
purity.
Most people think of a portable program as one that produces the same
results
on any platform. This is actually a very imprecise definition.
</quote>

This quote appears on page 15 of the PDF, and on page 16 they show an
example of 2 programs. Both are "portable", but one is "pure" while the
other one is not. They don't explain the distinction further (not as far as
I can see anyway).

<quote>
Variances were previously granted to developers making variance requests to
Sun's Variance Council.
</quote>

This refers to the fact that Sun used to distribute a tool to check for
"100% Pure Java" compliance by analyzing your Java source code. The tool
apparently gave some false positives, and rather than "fix" the tool (which
may have been on the same order of difficulty as solving the halting
problem), you would instead submit an explanation for your "variance" to
Sun's Variance Council.

I only skimmed over the PDF, but it seems quite obvious to me that the
term "100% Pure Java" is not very well defined at all. Incidentally, the
Google search also turned up this site:

http://tolstoy.com/impure.html

which claims to link to an internal Sun document written by the Program
Manager in which, basically, Sun admits that the term "100% Pure Java" is a
problematic one. Unfortunately, the link seems to be broken and I could not
find it via Google cache. If anyone could ressurect that document, I'd be
very interested to see it.

- Oliver
 
B

Benji

Roedy said:
There is on such thing as a Java program that uses no native methods.
The core methods of Java are necessarily native methods. That is not
what 100% pure java means.

OK, now you're just being a jerk. Either stop replying to him, or
explain what you mean.
 
L

Lasse Reichstein Nielsen

Pep said:
Roedy Green wrote:
You could argue that in Java they are still platform dependent, in that they
are set as per the Java VM (virtual machine) which is always the same
regardless of the physical machine that it is running on.

A more precise characterization of C++ would be that the size of the
"int" type is *implementation* dependent. You could easily make two
implementations with different size ints on the same platform that are
still compliant C++ implementations.

Since the Java Language Specification does not leave room to wiggle,
the size of the type "int" is not implementation dependent in Java.

Mentioning the platform is just causing confuzion.

/L
 
M

Monique Y. Mudama

On 2005-11-16, Roedy Green penned:

[snip]
Anything else important to say?

It's probably worth mentioning struct and union. A lot of C/C++
people just "assume" you can have a union in Java, and get all
blustery when they find out it's not there.
 
J

Jaakko Kangasharju

Roedy Green said:
A link to an essay on the differences between C++ and Java in the Java
glossary has died, so I concocted this little essay to replace it at
http://mindprod.com/jgloss/cpp.html

Anything else important to say?

In Java, the class hierarchy has the Object class as its root. C++
does not have a rooted class hierarchy.

In Java, method and field definitions must be inside some class. In
C++ you can also define functions and variables independently of
classes (and in fact, you don't need to define any classes to write
C++ programs).
 
P

Patrick May

Roedy Green said:
A link to an essay on the differences between C++ and Java in the
Java glossary has died, so I concocted this little essay to replace
it at http://mindprod.com/jgloss/cpp.html [ . . . ]
Java object code (class files containing JVM byte codes) will run
unmodified on any platform. C++ object code must be first linked to
produce an executable containing platform-specific machine
instructions. It will run only on one platform.
[ . . . ]

That's a bit harsh. In practice, C++ is roughly as portable as
Java, especially for typical business systems.
Anything else important to say?

A few things that come immediately to mind:

- C++ does not impose restrictions on file names, nor does it
limit the number of publicly visible classes that may be
implemented in a file.

- C++ supports the separation of declarations and definitions
into separate .h and .C files. Some developers prefer this to
Java's approach of putting everything in one file.

- C++ templates are more powerful (and correspondingly more
dangerous) than Java's generics.

- C++ can take advantage of C libraries more easily than can Java
via JNI.

- Where performance must be optimized, it is easier to call
assembler from C++.

- C++ presents a higher barrier to entry than Java. This is not
necessarily a bad thing. Any idiot can get something up and
running in Java. C++ requires that one be a more technically
sophisticated idiot.

This is not intended as a flame against either language. Both have
their place.

Regards,

Patrick
 
T

Thomas Hawtin

Patrick said:
- C++ templates are more powerful (and correspondingly more
dangerous) than Java's generics.

Differently powerful. C++ templates can't cope with the equivalent of
Java's wildcards in a reasonable manner. OTOH, C++ templates are
accidentally Turing-complete (so long as you ignore the some rather
narrow limitation of the spec).

Tom Hawtin
 
H

Hendrik Maryns

Robert Klemme schreef:
Interfaces

and multiple inheritance. And in C++ there is no root Object.
Abstract classes are done differently

MI in C++

Generics are different

Friendship does not exist in Java.
Java has built in Threading and synchronization mechanisms

As Oliver Wong pointed out, no expanded variables in Java, no reference
semantics either.

Nothing like Javadoc in C++.

H.
--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
 
R

Roedy Green

In Java, the class hierarchy has the Object class as its root. C++
does not have a rooted class hierarchy.

In Java, method and field definitions must be inside some class. In
C++ you can also define functions and variables independently of
classes (and in fact, you don't need to define any classes to write
C++ programs).

thanks everyone. You can see the aggregate list at
http://mindprod.com/jgloss/cpp.html
 
R

Robert Klemme

Hendrik said:
Robert Klemme schreef:

and multiple inheritance.

I mentioned MI.
And in C++ there is no root Object.

What exactly do you mean by this?
Friendship does not exist in Java.
True.


As Oliver Wong pointed out, no expanded variables in Java, no
reference semantics either.

Nothing like Javadoc in C++.

Well, there's doxygen... Anyway, both are not part of the language IMHO
so if pure language capabilities should be compared these don't count.

Kind regards

robert
 
P

Pep

Oliver said:
http://mindprod.com/jgloss/newsgroups.html#GIFTHORSE

My intent was to provide some constructive criticism. I apologize if I
was too subtle in my efforts. Here's the sequence of events, and the
rational for my actions from my perspective:

You wrote an essay about the difference between C++ and Java.
Pep pointed out some problems with the statement "Java is platform
independent".
You dismissed Pep's point.
I agree with the Pep's point, and wanted to indicate that he was not
the
only person to feel that the statement has some problems, which leads to
the possibility that other people may feel the same way too, but chose not
to post about it.
I (subtly?) ended my post with the advice of "consider your audience".
This is difficult in your (Roedy's) case, because the MindProd site is
oriented towards people with a technical background in Java, but to the
"newbie" segment of that population, so it is somewhat of a grey area
whether the essay should strive for technical correctness versus ease of
understanding. If I were faced with the same problem, I'd give the "easy
to understand" explanation first, with notes that there may be some
technical problems with it, and a link (perhaps as a footnote) to the more
complex, but technically correct answer.

In the end, it's your site, and your essay, so you can write whatever
you want. I had (perhaps incorrectly) assumed you were looking for some
feedback.

- Oliver

Wow, perhaps this is a case of too academic or too java centric?

I think that Roedy should lighten up a bit here. He asked for feedback
which I originally gave light heartedly and pointed out that I am not an
enemy of the "Java takeover the world" movement :)

I guess I should have read between the lines and seen that what he was
actually asking for feedback that agrees entirely with his point of view
and perhaps pats him on the back for being a clever little chappy and
definitely not anything slightly critical, even in jest.
 
H

Hendrik Maryns

Robert Klemme schreef:
I mentioned MI.

Ah sorry, didn't recognise the acronym.
What exactly do you mean by this?

What Jaakko Kangasharju said, C++ does not have a rooted hierarchy.
Well, there's doxygen... Anyway, both are not part of the language IMHO
so if pure language capabilities should be compared these don't count.

Don't know doxygen. (I'm not a C++ programmer, I only read about it...)

H.

--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
 
R

Roedy Green

I think that Roedy should lighten up a bit here. He asked for feedback
which I originally gave light heartedly and pointed out that I am not an
enemy of the "Java takeover the world" movement :)

I decided to plonk Oliver for a while to give it a rest. It was
getting too frustrating being contradicted over and over by someone so
inexperienced.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top