You are on page 1of 1

C++ Versus Java

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 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 The scope of an access control indicator in a class is limited to a single variable or function declaration statement Object is destructed whenever the Garbage Collection routine is automatically or manually invoked. 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 Exceptions can belong to any class or can even be a basic data type such as int or char or float or pointers like char * The scope of an access control indicator in a class spans until the next occurrence of such an indicator or until the end of the class declaration Object is destructed as soon as its scope is completed or when the delete operator is invoked to destroy dynamically created objects