What are the differences between C++ and Java?

What are the differences between C++ and Java?

by | 30-Mar-2020





Java language was invented by James A. Gosling

C++ was invented by professor Bjarne Stroustrup.

Java is Write Once Run Anywhere or Everywhere (WORA or WORE)

C++ is Write Once Compile Anywhere (WOCA)

Java is an Object Oriented Programming language.

C++ allows Procedural Programming, Functional Programming, Object-Oriented Programming, and template metaprogramming.

Call through the Java Native Interface and recently Java Native Access

Allows direct calls to native system libraries.

No native support for unsigned arithmetic.

Supports native unsigned arithmetic.

Supports only class and allocates them on the heap.

Supports class, struct, and union and can allocate them on heap or stack.

No support for Operator overloading.

Support for operator overloading

No function pointer mechanism. Instead Interfaces, Adapters and Listeners are extensively used.

Support for function pointer mechanism.

Java supports multilevel inheritance and does not support multiple inheritance but instead java supports multiple interface inheritance.

Support for both multilevel and multiple inheritance

Java does not support destructors but rather adds a finalize() method.

C++ can use destructors.

Javadoc provides standard documentation.

C++ does not provide any kind of documentation.

final keyword is used to declare constant variables.

const keyword is used to declare constant variables.

Java offers automatic garbage collection.

Memory management in C++ is usually done through constructors, destructors, and smart pointers.

Java allocates memory through object instantiation.

C++ can allocate arbitrary blocks of memory.

Java does not have global variables or functions because all the code in java program is encapsulated within the classes.

C++ have global variables or functions

Java is normally compiled to byte-code which the Java virtual machine (JVM) then either interprets or JIT compiles to machine code and then executes.

C++ is normally compiled directly to machine code which is then executed directly by the operating system.

Java provides multithreading capability.

C++ does not provide multithreading capacity.

Java does not support the goto statement However, it does support labeled break and continue statements.

C++ supports the goto statement.

There is no virtual keyword in Java.

Support for virtual keyword in C++.

The char type in Java is a 16-bit type and uses the Unicode character set (the Unicode values from 0 through 127 match the ASCII character set).

The char type in C++ is an 8-bit type that maps to the ASCII (or extended ASCII) character set.

Java is a platform-independent language

C++ depends upon the operating system

Java uses import to include different Classes and methods.

C++ support header file, include library files etc.

Java does not have a preprocessing phase.

C++ compilation features an additional textual preprocessing phase.

Java is a trademark of Sun Microsystems (Oracle).

C++ is not a trademark of any company or organization and is not owned by any individual.

The Java language is defined by the Java Language Specification.

The C++ language is defined by ISO/IEC 14882, an ISO standard committee.




There are no comments.

Enter a new Comment:

Copyright Šprgrmmng. All rights reserved.