R
Roedy Green
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?
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?