There are many differences between C++ and Java. However, the syntax of C++ and Java are similar.
Java is a purely object oriented programming language whereas C++ is an object oriented extension of C programming. C++ supports both procedural and object oriented programming. Here are the major differences between C++ and Java.
Difference Between Java and C++
Java | C++ |
---|---|
Java is purely Object-oriented programming language, since it is not possible to write a Java program without using at least one class. | C++ is not a purely object-oriented programming language. It is object oriented extension of C. It is possible to write C++ program without using a class or an object. |
Java does not support pointers. | C++ support pointers. |
Java doesn’t support Global variables. | Global variables can be declared in C++. |
Java support automatic garbage collection. However java does provide finalize method. | C++ support destructor functions, which gets called automatically whenever an object is destroyed. |
Java doesn't support multiple inheritance but there are other means to achieve it. | C++ support multiple inheritance. |
Java does not support conditional inclusion and compilation. | C++ supports conditional inclusion and compilation using #ifdef, #ifndef etc. |
Java does not support operator overloading, structures, union and templates. | C++ supports operator overloading, structures, union and templates. |
Java does not support goto jump statement. | C++ supports goto jump statement. Although, using goto is considered as bad programming practice. |
Java is platform independent. Because java is interpreted, same java program can run in multiple platform having JVM. | C++ is platform dependent. Same C++ code may not run on different platforms. |
Java doesn't support default argument to a function. | C++ supports default argument to a function. |
Java provides inbuilt support for documentation comments. Java provides a tool called javadoc, which reads all documentation comments from source code and convert it to HTML format. | C++ does not provide inbuilt support for documentation comments. |
Java provides inbuilt support for multi threading. | C++ does not have inbuilt support for multi threading. |
In Java, function arguments are always passed using call by value. There is support for call by reference. | C++ supports both call by value and call by reference. |