
C++ :-
C++ was designed for systems and applications programming, extending the C programming language. To this procedural programming language designed for efficient execution, C++ has added support for statically-typed object-oriented programming, exception handling, scoped resource management, and generic programming, in particular. It also added a standard library which includes generic containers and algorithms.
Java :-
Java was created initially as an interpreter for printing systems but grew to support network computing. Sun Microsystems used it for the basis of their "HotJava" thin client system. It relies on a virtual machine to be secure and highly portable. It is bundled with an extensive library designed to provide a complete abstraction of the underlying platform. Java is a statically-typed object-oriented language that uses a syntax similar to C++, but is not compatible with it. It was designed from scratch, with the goal of being easy to use and accessible to a wider audience.
The different goals in the development of C++ and Java resulted in different principles and design trade-offs between the languages. The differences are as follows :
Java versus C++: General programming issues
Java | C++ |
---|---|
Method bodies must be defined inside the class to which they belong. | Method bodies must be defined inside the class to which they belong. |
No forward referencing required. | Explicit forward referencing required. |
No preprocessor. | Heavy reliance on preprocessor. |
No comma operator. | Comma operator. |
No variable-length parameter lists. | Variable-length parameter lists. |
No optional method parameters. | Optional function parameters. |
No const reference parameters. | const reference parameters. |
No goto | goto |
Labels on break and continue. | No labels on break and continue. |
Command-line arguments do not include the program name. | Command-line arguments do not include the program name. |
Main method cannot return a value. | Main function can return a value. |
No global variables. | Global variables. |
Character escape sequences can appear in a program. | Character escape sequences must appear in a string or character literal. |
Cannot mask identifiers through scope. | Can mask identifiers through scope. |
Java | C++ |
---|---|
Pure object-oriented language. | Hybrid between procedural and object-oriented. |
All functions (methods) are part of a class. | Can have stand-along functions. |
No multiple inheritance. | Multiple inheritance. |
Formal interface specifications. | No formal interface specifications. |
No parameterized type. | Templates as parameterized type. |
No operator overloading. | Operator overloading. |
All methods (except final methods) are dynamically bound. | Virtual functions are dynamically bound. |
Java | C++ |
---|---|
Two type categories. | Various type categories. |
All nonprimitive types are objects. | Separate types for structs, unions, enums, and arrays. |
All numeric types are signed. | Signed and unsigned numeric types. |
All primitive types are a fixed size for all platforms. | Primitive type size varies by platform. |
16-bit Unicode characters. | 8-bit ASCII characters. |
Boolean data type primitive. | No explicit boolean data type. |
Conditions must be boolean expressions. | Integer results are interpreted as boolean conditions. |
Variables are automatically initialized. | No automatic initialization of variables. |
Java | C++ |
---|---|
References, with no explicit pointer manipulation and no pointer arithmetic. | Pointers, with dereferencing (* or ->) and address (&) operators. |
Array references are not translated to pointer arithmetic. | Array references translate to pointer arithmetic. |
Arrays automatically check index limits. | No automatically array bounds checking. |
Array lengths in multidimensional arrays can vary from one element to the next within one dimension. | Array lengths in multidimensional arrays are all the same size in a give dimension, fixed by the declaration. |
Strings are objects. | Strings are null-terminated character arrays. |
Built-in string concatenation operator(+). | String concatenation through a library function. |
Use string concatenation operator for long string literals. | Use line continuation (\) for long string literals. |
No typedef . | typedef to define types. |
Java | C++ |
---|---|
Specifically attuned to network and Web processing. | No relationship to networks or the Web. |
Automatic garbage collection. | No automatic garbage collection. |
Combination of compiled and interpreted. | Compiled. |
Slower execution when interpreted. | Fast execution. |
Architecture neutral. | Architecture specific. |
Supports multithreading. | No multithreading. |
Automatic generation of documentation in HTML format. | No automatic documentation generation |