There are many differences and similarities between the C++ programming language and the Java programming language. The list of top differences between them are given below:
Comparison Index | C++ | Java |
Platform Independent | C++ is platform dependent. | Java is platform-independent. |
Mainly used for | It is mainly used for system programming. | It is mainly used for application programming. It is widely used in windows, web-based, enterprise and mobile applications. |
Goto | C++ supports the goto statement. | Java doesn't support the goto statement. |
Multiple Inheritance | C++ supports multiple inheritance. | Java doesn't support multiple inheritance through class. It can be achieved by interfaces in java. |
Operator Overloading | C++ supports operator overloading. | Java doesn't support operator overloading. |
Call by Value and Call by reference | C++ supports both call by value and call by reference. | Java supports call by value only. There is no call by reference in java. |
Inheritance Tree | C++ creates a new inheritance tree always. | Java uses a single inheritance tree always because all classes are the child of the Object class in java. The object class is the root of the inheritance tree in java. |
NOTE:-
- Java doesn't support default arguments like C++.
- Java doesn't support header files like C++. Java uses the import keyword to include different classes and methods.
C++ Example
File: main.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello C++ Programming";
return 0;
}
Java Example
File: Simple.java
class Simple{
public static void main(String args[]){
System.out.println("Hello Java");
}
}