Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Differences between C++ and Java

Reply
Thread Tools

Differences between C++ and Java

 
 
Roedy Green
Guest
Posts: n/a
 
      11-16-2005
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

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.

In Java, garbage collection of unreferenced objects is automatic. In
C++, you manually manage memory.

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 Java you cannot overload operators. In C++, you can.

In Java, by default methods are virtual (overrideable). In C++, by
default, methods are non-virtual.

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.

Java checks all subscripts that they are in bounds and all casts for
validity. C++ does not.

Java requires a JVM to execute. C++ programs are usually freestanding.
Java does not use a preprocessor. C++ makes extensive use of a macro
preprocessor.

Anything else important to say?

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
 
Pep
Guest
Posts: n/a
 
      11-16-2005
Roedy Green wrote:

> 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
>
> In Java, the sizes of int, long etc. are rigidly defined in terms of
> bits. In C++ they are platform-dependent.
>


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.

> 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.


Again you could argue that in Java the endianess is platform dependent,
i.e.e as per the Java VM (virtual machine).

>
> In Java, garbage collection of unreferenced objects is automatic. In
> C++, you manually manage memory.
>


But this does not guarantee when the garbage collection will be performed in
Java, whereas in C++ you can determine when it will happen.

> 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 Java you cannot overload operators. In C++, you can.
>
> In Java, by default methods are virtual (overrideable). In C++, by
> default, methods are non-virtual.
>
> 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.
>


Again, arguably Java byte code will only run on one platform, i.e the Java
VM (virtual machine).

> Java checks all subscripts that they are in bounds and all casts for
> validity. C++ does not.
>
> Java requires a JVM to execute. C++ programs are usually freestanding.
> Java does not use a preprocessor. C++ makes extensive use of a macro
> preprocessor.
>
> Anything else important to say?
>


Not looking to cause an argument, just playing with words

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-16-2005
Roedy Green wrote:
> Anything else important to say?


Interfaces

Abstract classes are done differently

MI in C++

Generics are different

Java has built in Threading and synchronization mechanisms


If you start talking about standard library functionality then there's a
lot more.

robert

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-16-2005
On Wed, 16 Nov 2005 13:30:32 +0000, Pep <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>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.


Dependent implies change with the thing depended on changes. The
sizes are invariant in Java. They are part of the language spec. They
apply even when there is no JVM, e.g. Jet.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-16-2005
On Wed, 16 Nov 2005 13:30:32 +0000, Pep <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>Again you could argue that in Java the endianess is platform dependent,
>i.e.e as per the Java VM (virtual machine).


Unless there is something new in nio, I don't think you can get a
program to produce different endianness files or socket streams on
different machines with the same code. In other words, it does not
depend on the platform. That even applies to 64 bit jvms.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-16-2005
On Wed, 16 Nov 2005 13:30:32 +0000, Pep <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>
>But this does not guarantee when the garbage collection will be performed in
>Java, whereas in C++ you can determine when it will happen.


There is no official GC in C++ is there? It is always an add on. In
Java you can suggest when a good time to run might be, but you cannot
force it.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-16-2005
On Wed, 16 Nov 2005 13:30:32 +0000, Pep <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>>

>
>Again, arguably Java byte code will only run on one platform, i.e the Java
>VM (virtual machine).

You are in the wrong major. Take up corporate law.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-16-2005
On Wed, 16 Nov 2005 15:41:14 GMT, Roedy Green
<(E-Mail Removed) > wrote, quoted or
indirectly quoted someone who said :

>>Again, arguably Java byte code will only run on one platform, i.e the Java
>>VM (virtual machine).

> You are in the wrong major. Take up corporate law.


In java terminology Platform-independent refers to the ability to run
Java byte code on many different platforms if they have a JVM
implementation.

Platform refers then not to the JVM but to the OS and hardware that
host it.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Pep
Guest
Posts: n/a
 
      11-16-2005
Roedy Green wrote:

> On Wed, 16 Nov 2005 15:41:14 GMT, Roedy Green
> <(E-Mail Removed) > wrote, quoted or
> indirectly quoted someone who said :
>
>>>Again, arguably Java byte code will only run on one platform, i.e the
>>>Java VM (virtual machine).

>> You are in the wrong major. Take up corporate law.

>
> In java terminology Platform-independent refers to the ability to run
> Java byte code on many different platforms if they have a JVM
> implementation.
>
> Platform refers then not to the JVM but to the OS and hardware that
> host it.


Like I said, I'm only playing on words.

Please don't get me wrong, I find Java to be a really useful language and
certainly prefer the extensibility and ease of use of the language compared
to that of C++.

Pep.

 
Reply With Quote
 
AndyRB
Guest
Posts: n/a
 
      11-16-2005
Roedy Green wrote:
> On Wed, 16 Nov 2005 15:41:14 GMT, Roedy Green
> <(E-Mail Removed) > wrote, quoted or
> indirectly quoted someone who said :
>
> >>Again, arguably Java byte code will only run on one platform, i.e the Java
> >>VM (virtual machine).

> > You are in the wrong major. Take up corporate law.

>
> In java terminology Platform-independent refers to the ability to run
> Java byte code on many different platforms if they have a JVM
> implementation.


Which is alot more accurate than you original statement:
"Java object code (class files containing JVM byte codes) will run
unmodified on any platform"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DEVELOP THE WINNING EDGE, SMALL DIFFERENCES IN YOUR PERFORMANCE CANLEAD TO LARGE DIFFERENCES IN YOUR RESULTS Home_Job_opportunity C Programming 0 01-14-2009 03:51 PM
DEVELOP THE WINNING EDGE, SMALL DIFFERENCES IN YOUR PERFORMANCE CANLEAD TO LARGE DIFFERENCES IN YOUR RESULTS Home_Job_opportunity C Programming 0 01-08-2009 04:31 PM
Differences between one-dimensional arrays in Java and C Paul Morrison Java 1 05-01-2005 04:37 PM
Differences between C++ and Java with this-pointer Rasti C++ 5 11-06-2003 02:39 AM
Differences between C++ and Java cyberdude Java 36 09-17-2003 01:36 AM



Advertisments