Differences between C++ and Java

L

ldv

Oliver said:
I've never used the JET products, but from my understanding of the
excerpt you gave, there are two products here: One is called "Excelsior JET
Optimizer" and the other is "Excelsior JET Runtime". While "Runtime" is
indeed a JVM, the excerpt makes it sounds like "Optimizer" is a compiler
which can produce native Intel x86 executables which can run without a JVM.

No, these are two components of one product. They do not work without
each other. The third component is the installation toolkit that
enables you to create installers for your native-compiled Java apps.

LDV
 
R

Roedy Green

This seems oddly inconsistent with your claim that we should follow
only the words in the discussion while disregarding the author.

I am having trouble with the things Oliver is saying. In my proposed
experiment, you would still be able to plonk anonymous voices. The
idea was you just you don't prejudge every statement by who said it.
You might get away from the ego games of who said X first, who made a
mistake, who caught it, whose on my side, who is part of X's posse.
The game I would hope would diminish is where A makes a statement. B
says "It's wrong". A says that's not what I meant. B says "Yes you
did, therefore you are an idiot, POINT!"

I think all newsreaders should have a timeout on a plonk, so that you
review the behaviour every once in a while.

Plonking is not like banning someone to outer darkness. Other people
can still converse. You can look on it like trimming your set of
magazine subscriptions to a reasonable number. You can't read
everything, so you might as well be selective.
 
R

Roedy Green

No, these are two components of one product. They do not work without
each other. The third component is the installation toolkit that
enables you to create installers for your native-compiled Java apps.

Prior to JET 4.0, JetPerfect could produce standalone executables
containing just the Sun classes required. Now, the new Sun/Excelsior
licence agreement means Jet must distribute a DLL containing the
entire JVM with each application.

The don't need to distribute the class files or the JDK however.
 
R

Roedy Green

I am honestly baffled at some of your recent posts. You have sometimes
taken what seem to be logically inconsistent stances, and you have taken
offense where I believe none was intended.

I can't respond to a broad brush charge like that. Please enumerate
these stances.

In the debate about ternary for example, I felt you were being unfair
by using a straw men argument. I explained the definition of clarity I
was using when I claimed it was possible to objectively measure it.
You could even do it with a multiple choice test.

Thomas did not originally intended to offend, and his continued use of
the insult is definitely intended to offend. It is a **** you. I was
not asking much, just that he stop comparing all my posts to worthless
disgusting slime.

If he did that to random strangers on the street, he would have a nose
beaten to a pulp by now.

I am quite ill with HIV. I feel all the time as though I had just
completed a marathon, even after a 12 hour sleep. My muscles are like
rubber. I am less resistant than usual to the slings of Internet
discussion. I have to withdraw from the people that I am getting in
fights with. I have very little energy each day and it is maddening
when it gets frittered in bickering.

At the same time, I figure I owe people an explanation why am cutting
them off.

There seem so be something in the air. Congress and the Senate too are
at each other's throats.
 
M

Monique Y. Mudama

I can't respond to a broad brush charge like that. Please enumerate
these stances.

I questioned whether to post that even as I did, in part because I
don't have the interest in backing it up with specifics, and in part
because even if I did, it would simply lead to an argument with no
point. It would be he said/she said, literally. It's simply an
impression I've gotten. It wasn't so much intended as an attack on
you, but it's hard to say something like that without coming across
that way. It's more like, hey, Roedy, maybe you could consider going
a little easier on people?

[snip]
Thomas did not originally intended to offend, and his continued use
of the insult is definitely intended to offend. It is a **** you. I
was not asking much, just that he stop comparing all my posts to
worthless disgusting slime.

If he did that to random strangers on the street, he would have a
nose beaten to a pulp by now.

Okay, see, this is where I completely disagree with you. Personally,
I find your attribution line, or more accurately, its implied
disregard for quoting accurately, to be extremely irritating; whereas
Thomas' attribution line slips under my radar and wouldn't even have
have been noticed by me if you didn't keep bringing it up. Your
dislike for accurately quoting a person is considered a Big Deal in
netiquette; people in most newsgroups apologize for misattributions.
Whereas silly attribution lines are pretty common, and almost
universally ignored. To my mind, *your* attribution is the one that
offends and is a "**** you," because it says that you have so little
respect for us that you don't even care to get our names right. But
note that I've never gone on a campaign to get you to change it,
although I have commented on it snidely a few times. I never
suggested you should have your nose punched in because of it.

We are in usenet, which has different etiquette than the street. He's
not really comparing all your posts to worthless slime, as the content
of his responses doesn't in any way suggest that he feels your posts
are worthless. It's a silly attribution, and it's not harming anyone,
and you're freaking out about it, and I find your response, as I said
earlier, baffling. I don't know if he's only using that attribution
line for you, now, to tweak you, but I'm dead certain it started out
as a generic attribution line for anyone.

I can't even think of anything analogous to an attribution line "in
real life", so I can't follow that analogy.
I am quite ill with HIV. I feel all the time as though I had just
completed a marathon, even after a 12 hour sleep. My muscles are
like rubber. I am less resistant than usual to the slings of
Internet discussion. I have to withdraw from the people that I am
getting in fights with. I have very little energy each day and it is
maddening when it gets frittered in bickering.

At the same time, I figure I owe people an explanation why am
cutting them off.

I guess my feeling is that there's no need to fight; no need at all.

When I get tired of a discussion, I just stop posting, or maybe post to
say, "I'm not interested in continuing this discussion, as it's not
going anywhere." I don't resort to calling people names (ie
whippersnapper; if Oliver is a whippersnapper, I'm not far off, either,
having never bothered to write an interpreter, whatever that has to do
with anything. And my only exposure to assembler was a truly awful
teacher for one class in college). I feel like sometimes you can be
quite rude to people, without any justifiable grounds. But frankly,
even when rudeness is justified, it's still better to take the high
ground. I find that people respect that.
There seem so be something in the air. Congress and the Senate too
are at each other's throats.

Perhaps.

I can understand being ill and having a short temper because of it. I
really can, and if I could make you feel better, I would in a
heartbeat. Please know that. I admire your desire to make a
difference in the world by helping others. And we all sometimes say
grumpy things, or things that sound grumpy or uncharitable, in text.
It's the nature of the beast. I just firmly believe that "you catch
more flies with honey," and I think that when you establish a posting
history that is speckled with grumpiness, you're working at cross
purposes to your goal. People who would otherwise learn from you will
cut you off.

Anyway, I don't want to be hurtful to you, and I don't really think
continuing this discussion would be productive. Either you will
recognize what you are doing and put effort towards changing it, or you
will not recognize it and simply be offended or baffled. And of course
there's a chance that I am the only person who sees this trend, that
it's all in my imagination, etc. That's possible, too.

I wish you well and I hope that you will feel at least a little bit
better in the near future.
 
D

Dimitri Maziuk

Roedy Green sez:
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?

You're kidding, right?

How about

Guaranteed object destruction
Choice of stack or heap allocation
Template metaprogramming
Constructor inheritance
const references

-- to name a few off the top of my head and in no particular order.

Dima
 
R

Roedy Green

You're kidding, right?

No I was not. Potentially the list could go on for a whole book
detailing all the differences. My question was about the IMPORTANT
differences. I wanted to give others a chance to get their two cents
in on what they considered important.
Guaranteed object destruction
Choice of stack or heap allocation
Template metaprogramming
Constructor inheritance
const references

I have added your points to the list. Some of your points were
elaborations of points already there.
 
O

Oliver Wong

Monique Y. Mudama said:
if Oliver is a whippersnapper, I'm not far off, either,
having never bothered to write an interpreter, whatever that has to do
with anything. And my only exposure to assembler was a truly awful
teacher for one class in college).

Just for the record, and for what it's worth, I sort of write
interpreters for a living (I write "compiler-like" tools). You'll see me
posting on alt.lang.cobol, for example, asking the regulars there questions
about the semantics of various keywords, because I'm working on a COBOL
interpreter.

As for assembler, like Monique, it was only in an academic setting.

- Oliver
 
D

Dimitri Maziuk

Roedy Green sez:
No I was not. Potentially the list could go on for a whole book
detailing all the differences. My question was about the IMPORTANT
differences.

Yeah, that's what I meant. You're comparing Java with "C with
classes", resulting in apples and oranges list. You should be
comparing Java with the modern C++ as used for proper OO.

(Unfortunately, few places teach C++ that way. Even worse, most
users use C++ as "C with iostreams".)
In Java, the sizes of int, long etc. are rigidly defined in terms of
bits. In C++ they are platform-dependent.

In Java, the JVM behaves at if it were big endian, even if internally
it is actually little-endian. In C++, the endianness is platform
dependent.

Java object code (class files containing JVM byte codes) will run
unmodified on any platform.

Java requires a JVM to execute.

The IMPORTANT bit here is that Java is a Platform -- usually
implemented as virtual machine running on top of actual
hardware/os platform. The fact that Java platform is big-endian,
has 32-bit int, and has its own executable format is an obvious
implementation detail. C++, OTOH, runs on top of hardware/os
platform and has to deal with all those things.

Furthermore, Java platform also has standardized GUI, threading,
DB connectivity, e-mail, etc. API where C++ has to rely on
platform-specific libraries.
In Java, references are constrained to point only to the beginnings of
objects. In C++, you can do arithmetic on pointers and make pointers
point anywhere in the address space.

In C++ you can't do address arithmetic on references or point them
to anywhere in address space either.
(Generally, you'll almost never need address arithmetic if you're
using modern C++ in OO fashion. The whole "pointers" thing is mainly
due to a) C++ being commonly viewed as "C with classes" and b)
address arithmetic being the favourite scarecrow of automatic garbage
collection advocates.)

The important part here is that C++ exposes both the stack and the
heap to you and gives you tools to manage the latter.
In Java, garbage collection of unreferenced objects is automatic. In
C++, you manually manage memory.

FVO "manually" that include auto_ptr and destructors. It's the
consequence of having access to the heap -- if you manually allocate
something with "new", you must manually "delete" it later.

The important part is that behaviour of native and user types depends
on where they are allocated. In C++ they behave consistently, in Java
objects are passed by reference and natives are passed by value.

Other important consequences: for gc to work, Java must ensure that
all heap-allocated data carries the required magic. That is
implemented by reducing UDT's to just "Class" and making sure every
one of them inherits from "Object". Hence, no structs or unions in
Java, and a single-root hierarchy.

The important part is that C++ grew out of a glorified assembler,
and Java grew out of a language for programming microwave ovens.
Everything else is a consequence of that.

Dima
 
A

AndyRB

Roedy 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

My comments:
"In Java, the sizes of int, long etc. are rigidly defined in terms of
bits. In C++ they are platform-dependent. "

Technically this is inaccurate as the sizes of built-in types in c++
are *implementation* defined and the standard also specifies the
miniumum sizes of types and the size relationship between then:
char - 8 bit, -127 to +127 when signed
short - plus or minus 32767 (2**15)
int - plus or minus 32767
long - plus or minus 2147483657 (2**31)

char <= short <= int <= long.

"In Java, garbage collection of unreferenced objects is automatic. In
C++, you manually manage memory. In Java you don't know for sure that
all finalizers will be run; in C++ you do, because you invoke them
manually. You could of course write a manual close method for Java
objects. In Java, the choice of stack of heap allocation is handled
automatically by the compiler (Sun's javac is not very bright always
using the heap for objects). In C++ you control it manually. "

There is more than one type of memory in c++, for example a variable
declared as having automatic storage duration will be automatically
managed (deallocated and destructor called). So it would be more
accurate to specify the type of memeory, i.e. memory is manually
managed when using dynamic memory. There are no finalizers in c++ and
although there are destructors which you can invoke manually
"ObjectName.~classname()", doing so would often result in undefined
behaviour (very rarely done except in low-level code - i.e.
implementation of std::vector).

"In Java, references are constrained to point only to the beginnings of
objects. In C++, you can do arithmetic on pointers and make pointers
point anywhere in the address space. "

I understand what you are saying here, but in c++ you can legally only
point to an object or one past the end of a object, otherwise you have
undefined behaviour. But obviously it is up to the programmer in this
case to ensure they do not invoke undefined behaviour, the language
will not enforce/check this.

"Java checks all subscripts that they are in bounds and all casts for
validity. C++ does not. "
You are right that C++ does not check *all* subscripts and *all* casts
but it does check some. For example, when using c++ style casting,
rather than a traditional C cast.

"Java has a vast standard library set, including AWT and Swing. C++ has
a relativey modest standard set of methods, and relies on
platform-specific GUI libraries."

A difference you could mention the fact that the c++ standard library
is typically more template / generic based rather than object oriented.
The library is implemented in standard c++, therefore anyone can
provide third party libraries that work just as well, so although it
would be good if more functionality was standardized, it is not
necessarily required.
The fact that the c++ standard library is part of an ISO standard and
must be portable across many "platforms" which have far less
requirements than the JVM (i.e. no requirement for a display or hard
drive), certainly makes a difference. The library and the language
satisfy only the core requirements and has a far more limited scope
than the Java library. Third party library play an important part in
c++ and always will.

"In C++ constructors inherit. In Java, constructors are redefined for
every subclass."
This is not true, constructors in c++ do not inherit.

"Java has the final keyword and C++ has const. C++ gives you finer
control, but that control can be overridden with a cast. "
Not really. In c++ you can usually always lie to the compiler, but...

const int const_val = 5;
int & val_ref = const_cast<int&>(const_val);
val_ref = 6; //undefined behaviour.

In the above the const cast is OK, but the underlying variable
const_val remains const (it may, for example, have been place in an
area of memory marked as read-only). The result is any attempt to
modify it is illegal - undefined behaviour.

Other main differences:
- c++ the language and it's standard library are defined by a ISO
standard.
- deterministic destruction (this is very important from a c++ point of
vioew).
- exception handling and specifically exception specifications
- different philosophies / goals.
 
R

Roedy Green

The fact that Java platform is big-endian,
has 32-bit int, and has its own executable format is an obvious
implementation detail. C++, OTOH, runs on top of hardware/os
platform and has to deal with all those things.

It is not an implementation detail. It is part of the language spec.
That is one of the big ways Java and C/C++ differ. Java programs have
to work AS IF big endian hardware were used. C/C++ programs follow the
hardware.
..
The JVM is implemented on Windows pure little endian inside. The only
time it gets converted to big endian is in DataOutputStream. However,
that is sufficient to maintain the illusion.

Java does not let you overlay bytes on top of ints the way you can in
C/C++ so you can't determine the platform endianness that way.
 
R

Roedy Green

In C++ you can't do address arithmetic on references or point them
to anywhere in address space either.

C++ is a strict superset of C. If you can do it in C, you can do it
in C++. Of course you might sensibly refrain from using those
dangerous features in C++, but they are still at your elbow.
..
 
R

Roedy Green

Other important consequences: for gc to work, Java must ensure that
all heap-allocated data carries the required magic.

What "magic" are you talking about? do you mean a hidden flag to use
for live tallying?
 
R

Roedy Green

The important part is that C++ grew out of a glorified assembler,
and Java grew out of a language for programming microwave ovens.
Everything else is a consequence of that.

Amen!
 
R

Roedy Green

int - plus or minus 32767

What a joke! How can you write portable code with a guaranteed int
limit that small? You end up in C++ having to define portable types
with sensible sizes then mapping them onto whatever you can find in
the implementation.
 
R

Roedy Green

"In Java, references are constrained to point only to the beginnings of
objects. In C++, you can do arithmetic on pointers and make pointers
point anywhere in the address space. "

I understand what you are saying here, but in c++ you can legally only
point to an object or one past the end of a object, otherwise you have
undefined behaviour. But obviously it is up to the programmer in this
case to ensure they do not invoke undefined behaviour, the language
will not enforce/check this.

A C++ pointer can also point into the middle of an array or string, or
use a byte pointer to the low or high bytes of an int. These are all
allowed by the compiler and generate working code.

If you ever coded in PDP-11 assembler you can see where some of C's
features came from, including 16 bit indexing,
auto-pre/post/increment/decrement and use of pointer arithmetic
instead of indexing.
 
R

Roedy Green

The fact that the c++ standard library is part of an ISO standard and
must be portable across many "platforms" which have far less
requirements than the JVM (i.e. no requirement for a display or hard
drive), certainly makes a difference. The library and the language
satisfy only the core requirements and has a far more limited scope
than the Java library. Third party library play an important part in
c++ and always will.

So the compare one of the stripped down Java's with C++. Lack of
libraries can't be considered a virtue. If you wanted you could
ignore the Java libraries and write your own too. IBM wrote SWT.
 
T

Thomas Hawtin

Roedy said:
C++ is a strict superset of C. If you can do it in C, you can do it
in C++. Of course you might sensibly refrain from using those
dangerous features in C++, but they are still at your elbow.

That's not quite true. C++ is a near superset of C, as C stood in 1997.
For instance, const means different things in the two languages. C was
updated in 1999 with less emphasis on compatibility with C++ (there's
little point in having the two languages treading on each others toes).



It's normal to consider that "programming in C++" is not an adequate
description of "programming in C", even though it may be technically
accurate (to some extent). To say "C++", is usually to imply at least a
low-church C++ programming style.

Tom Hawtin
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top