Tuesday, July 25, 2006

Java Vs C++

Java Vs C++

FEATURES PRESENT IN C++ AND ABSENT IN JAVA:
Pointers – Referencing and Dereferencing arbitrary memory locations
Reference Variable – To explicitly allow both calls by value and reference without use of pointers
Structures and Unions – Packing aggregate data types into named contiguous memory locations
Global Data – To facilitate modular software development using shared data paradigm
Implicit Typecasting – Automatic casting of data to the best fitting compatible data types
Operator Overloading – Syntactic sugar used to modify operator semantics relative to a class
Destructors – To free dynamic memory and finalize an object at its exact time of destruction
Multiple Inheritance – Multiple base classes for a derived class in an inheritance network
Default Arguments – Default values for function arguments if not explicitly specified in a program
FEATURES PRESENT IN JAVA AND ABSENT IN C++:
Unicode support – Allows international character sets to be encoded in a java character or string
Garbage Collection – Automatic Finalization of objects when the Reference Counter hits zero
Packages – To group like classes into a single namespace called a package
>>> – The unsigned right shift operator in addition to other C++ bitwise operators
Documentation Comments – For automatic documentation generation using “javadoc”
Interfaces – A Class prototype with no implementation, to allow flexible inheritance and callbacks
Labeled Break and Continue – To resolve any ambiguity relating to the target of a break/continue
OTHER DIFFERENCES:

JAVA C++
Java has built-in multithreading support in the
form of Thread classes, synchronization
primitives, mutual exclusion etc.

The Boolean Data type cannot be treated as an
integer with 0 or 1 values

Thrown exceptions must have a handler which
either handles the exception’s class or one of
its base classes

All exceptions must be classes derived from a
inheritance network whose root is the
Throwable class


C++
OS dependent external libraries like POSIX
Threads, Win32 Threads have to be used to
implement multithreaded applications

C++ internally represents Booleans as follows
false = 0, true = any non-zero value

Exceptions need not be caught in C++. Such
unhandled exceptions are handled by calling
the “abort” routine to terminate the program

The scope of an access control indicator in a
class is limited to a single variable or function
declaration statement

No comments: