What are the differences between C++ and Java?

The differences between C++ and Java are given in the following table.

Comparison IndexC++Java
Platform-independentC++ is platform-dependent.Java is platform-independent.
Mainly used forC++ is mainly used for system programming.Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications.
Design GoalC++ was designed for systems and applications programming. It was an extension of C programming languageJava was designed and created as an interpreter for printing systems but later extended as a support network computing. It was designed with a goal of being easy to use and accessible to a broader audience.
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 can be achieved by interfaces in java.
Operator OverloadingC++ supports operator overloading.Java doesn’t support operator overloading.
PointersC++ supports pointers. You can write pointer program in C++.Java supports pointer internally. However, you can’t write the pointer program in java. It means java has restricted pointer support in Java.
Compiler and InterpreterC++ uses compiler only. C++ is compiled and run using the compiler which converts source code into machine code 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 is no call by reference in java.
Structure and UnionC++ supports structures and unions.Java doesn’t support structures and unions.
Thread SupportC++ 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 create documentation for java source code.
Virtual KeywordC++ supports virtual keyword so that we can decide whether or not override a function.Java has no virtual keyword. We can override all non-static methods by default. In other words, non-static methods are virtual by default.
unsigned right shift >>>C++ doesn’t support >>> operator.Java supports unsigned right shift >>> operator that fills zero at the top for the negative numbers. For positive numbers, it works same like >> operator.
Inheritance TreeC++ creates a new inheritance tree always.Java uses a single inheritance tree always because all classes are the child of Object class in java. The object class is the root of the inheritance tree in java.
HardwareC++ is nearer to hardware.Java is not so interactive with hardware.
Object-orientedC++ is an object-oriented language. However, in C language, single root hierarchy is not possible.Java is also an object-oriented language. However, everything (except fundamental types) is an object in Java. It is a single root hierarchy as everything gets derived from java.lang.Object.