JAVA V/S C++

There are many differences between the C++ programing language and Java.

IndexC++ Java
Platform-independentC++ is platform-dependent. Java is platform-independent.
UsedC++ is especially used for system programming. Java is especially used for application programming. It's widely utilized in window, web-based, enterprise and mobile applications.
Design Goal C++ was designed for systems and applications programming.It was an extension of C programing language. Java was designed and created as an interpreter for printing systems but later extended as a support network computing.
GotoC++ supports the goto statement. Java doesn't support the goto statement.
Multiple inheritanceC++ supports multiple inheritance. Java doesn't support multiple inheritance through class. It are often achieved by interfaces in java.
Operator OverloadingC++ supports operator overloading. Java doesn't support operator overloading.
PointersC++ supports pointers. You'll write pointer program in C++. Java supports pointer internally. However, you can not write the pointer program in java.
Compiler and InterpreterC++ uses compiler only. C++ is compiled and run using the compiler which converts ASCII text file into machine language so, C++ is platform dependent. Java uses compiler and interpreter both. Java source code is converted into bytecode at compilation time. The interpreter executes this bytecode at runtime and produces output. Java is interpreted that is why it is platform independent.
Call by Value and Call by referenceC++ supports both call by value and call by reference. Java supports call by value only. There's no call by reference in java.
Structure and Union C++ supports structures and unions. Java doesn't support structures and unions.
Thread C++ doesn't have built-in support for threads. It relies on third-party libraries for thread support. Java has built-in thread support.
Documentation commentC++ doesn't support documentation comment. Java supports documentation comment (/** ... */) to make documentation for java file.
Virtual Keyword C++ supports virtual keyword in order that we will decide whether or not override a function. Java has no virtual keyword. We will override all non-static methods by default. In other words, non-static methods are virtual by default.
Inheritance TreeC++ creates a new inheritance tree always. Java uses one inheritance tree always because all classes are the child of Object class in java. The object class is that root of the inheritance tree in java.
HardwareC++ is nearer to hardware. Java isn't so interactive with hardware.
Object-oriented C++ is an object-oriented language. Java is an Pure object-oriented language. However, everything (except fundamental types) is an object 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 incorporate different classes and methods.

C++ Example: -

#include <iostream>
using namespace std;

int main() {
cout << "Hello World"; // prints Hello World
return 0;
}


Java Example: -

public class Simple {

public static void main(String []args) {
System.out.println("Hello World"); // prints Hello World
}
}