How is Java different from C++? Compare both of them.

Following are the key differences between C++ and Java.

  • Java is platform independent whereas C++ is not.

  • Everything should be class in Java. No global function. No global data. No structs, no union.

  • There is no scope resolution operator :: in java.

  • Objects can only be created using new operator in java.

  • No preprocessor like macros in java.

  • Primitive data types in java are guaranteed to be initialized in java.

  • Packages instead of namespaces.

  • No pointers.

  • No destructors in objects.

  • No default arguments.

  • No goto statements.

  •  No templates or parameterized types.

  •  No inline methods.

  •  No multiple inheritance.

  •  No operator overloading.