Are c++ features a subset of java features?

A

Alf P. Steinbach

* Jon Harrop:
1. Execute code at compile time thanks to C++'s Turing-complete type system.

2. Low-level access to data structure internals, so you have more control
over memory usage.

3. Write unsafe code that accesses raw memory locations.

4. Operator overloading.

Both C++ and Java lack lots of features found in other languages, of course.

Of course Java can do a lot of things that C++ can't in a reasonable way
(but one example, safe applets), but to the above list I'd add as most
important,

0. C++ can interface to (or be used to implement!) OS or other
API functions, and in general, assembler language.

For example, the virtual platform that Java code runs on is implemented
in C and/or C++; Java's platform /independence/ is directly implemented
in terms of C and C++ platform /availability/.

C++ is a combination of systems-programming language, application/system
glue language, and application language. Java is a pure application
language. In pure Java you're restricted to the virtual Java universe
(not that that's bad, it's useful e.g. for productivity, but it's a
restriction), while in C++ you're in a mostly infinite universe,
although one with certain barred areas (such as applets, unless you're
willing to use a technology like Microsoft's ActiveX controls).
 
J

Jon Harrop

Alf said:
For example, the virtual platform that Java code runs on is implemented
in C and/or C++; Java's platform /independence/ is directly implemented
in terms of C and C++ platform /availability/.

In theory, you don't need C or C++ to implement Java.
C++ is a combination of systems-programming language, application/system
glue language, and application language. Java is a pure application
language. In pure Java you're restricted to the virtual Java universe
(not that that's bad, it's useful e.g. for productivity, but it's a
restriction), while in C++ you're in a mostly infinite universe,

"mostly infinite"? :)
 
J

Jon Harrop

Erik said:
Well, I don't know of any comparison but personally I'd say that C++ is
a superset of Java, way more powerful.

C++ doesn't even have garbage collection and it isn't cross platform.
 
B

Bo Persson

Jon said:
In theory, you don't need C or C++ to implement Java.

You mean we could use Fortran?

Or code the JVM in pure Java? That would assure universal portability. :)


Bo Persson
 
J

Jorgen Grahn

Want to do OOP. Does c++ have all the abilities of java, or is it some
subset?

Despite superficial similarities, Java and C++ are different languages.
Neither is a subset, even though Java used to be marketed as a
simplification of C++.

Solve a real-world problem well in Java, and solve it well in C++. Chances
are they solutions will both be good, but very different.

Key features are, IMHO, Java's garbage collected objects versus C++'s RAII
and almost cost-free small classes.

/Jorgen
 
P

peter koch

Jon Harrop skrev:
C++ doesn't even have garbage collection and it isn't cross platform.
If anyone wants to have garbage collection with C++, they install a
garbage collector such as the Boehm one. Also, C++ is available on far
more platforms than Java. Apart from that I sort of agree with you.

/Peter
 
J

Jon Harrop

peter said:
If anyone wants to have garbage collection with C++, they install a
garbage collector such as the Boehm one.

Then they're still lacking safety.
Also, C++ is available on far
more platforms than Java. Apart from that I sort of agree with you.

IME, C++ programs require many changes to run on a different platform
whereas Java programs require none.
 
J

Jon Harrop

Bo said:

That isn't part of C++. Even with a pseudo-GC like Boehm's, you still lack
safety, efficiency (ok, so does Java), marshalling and many other features.
Java isn't cross platform at all, it only runs on the JVM.

Which has been ported to many platforms.
To move Sun's Open Source Java to a new target, you first have to port a
C++ compiler.

The most common platforms are existing targets.
 
P

Pete Becker

Jon said:
That isn't part of C++. Even with a pseudo-GC like Boehm's, you still lack
safety, efficiency (ok, so does Java), marshalling and many other features.

I see. If it's not part of the language specification, it doesn't exist.
Sorry, but that's another myth promoted through Java marketing. The fact
is that if you want GC in C++ it's available to you. But you're not
forced to use it. Marshalling has been done in C and C++ for a long
time. Java didn't invent it. Same thing for "many other features".

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
P

Pete Becker

Jon said:
Then they're still lacking safety.

Again with the undefined terms. More Java marketing.
IME, C++ programs require many changes to run on a different platform
whereas Java programs require none.

Yup. Write once, run anywhere. Does anybody outside of Java's marketing
department actually believe that today? Even James Gosling qualified it:
"write once (carefully), run anywhere (mostly)."

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
P

Pete Becker

Jon said:
Or assembler, BCPL...


Most language implementations are bootstrapped.

Once you have a C++ compiler that generates machine code for a
particular platform you're all set. Unlike Java, uou don't need to
install a separate runtime environment to get your application to run.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
J

Jon Harrop

Pete said:
I see. If it's not part of the language specification, it doesn't exist.
Sorry, but that's another myth promoted through Java marketing. The fact
is that if you want GC in C++ it's available to you. But you're not
forced to use it. Marshalling has been done in C and C++ for a long
time. Java didn't invent it. Same thing for "many other features".

This is about language features. All of those features come with Java. None
come with C++. Some can be retrofitted but will never work as well as a
system designed for them (e.g. GC).
 
J

Jon Harrop

Pete said:
Once you have a C++ compiler that generates machine code for a
particular platform you're all set. Unlike Java, uou don't need to
install a separate runtime environment to get your application to run.

True. Although I expect there are Java -> standalone exe compilers out
there.
 
P

Pete Becker

Jon said:
This is about language features. All of those features come with Java. None
come with C++.

I see. If it's not part of the language specification, it doesn't exist.
Sorry, but for people who write code for a living (unlike marketing
hacks), this is nonsense.
Some can be retrofitted but will never work as well as a
system designed for them (e.g. GC).

Do you have any actual evidence to support that sweeping claim?

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

This is about language features. All of those features come with Java. None
come with C++. Some can be retrofitted but will never work as well as a
system designed for them (e.g. GC).

In that case I'd say Java loses much of it's winning points, the
extensive library for example. Without it Java would probably not be
near as big as it is today.
 
P

Pete Becker

Jon said:
True. Although I expect there are Java -> standalone exe compilers out
there.

Indeed. EDG has one, and it works with Dinkumware's Jcore library, most
of which I wrote. And, oddly enough, code that compiles just fine with
Sun's compiler sometimes doesn't compile with EDG's, except in
bug-compatible mode. So Java's claimed portability comes from using one
compiler only, and that one doesn't actually follow the published
specification.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 

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,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top