C++ vs Java
Both C++ and Java are high level programming languages which come under 4th Generation languages. Both are Object Oriented Programming Languages. But, They do share some differences between them. Check out the Differences between C++ and Java.
C++
- C++ (earliar known as C with Classes) was developed by Bjarne Stroustrup in 1979 at Bell Labs.
- C++ make use of Pointers and References
- C++ binary is not portable meaning binary cannot be run on different OS Platforms.
- C++ supports Multiple Inheretence through usage of Virtual Inheritance.
- Dynamic Polymorphism is achieved using Virtual Keyword (use of Virtual Pointer [VPTR] and VTable)
- C++ doesn’t support Memory Management. The progammer has to take care of Memory Allocation and Deallocation with the operations like New, Delete, Malloc, Calloc and use of Destructors (virtual destructors in case of virtual inheritance)
- C++ uses Collections by using STL (Standard Template Library). Its a third-party API
- C++ can have Global functions or Global variables which are outside the class
- C++ uses namespaces.
Java
- Java was developed by James Gosling in 1995 at Sun Microsystems (now acquired by Oracle Corporation).
- Java uses only References. Pointers are eliminated in Java to remove the complexity from the Programmers.
- Java code is portable and is achieved using Java Bytecode (.class) file which can be executed by JVM (JVMs differ based on the OS).
- Java doesn’t support Multiple Inheretence (because of Daimond Problem), But supportsInterface Inheritance using Interface.
- Dynamic Polymorphism is achieved using Method Overiding
- Java support Automatic Memory Management using Garbage Collector. The GarbageCollector is a Daemon thread which keeps scanning the memory and clears the objectswhen the memory is low or required.
- Java API comes with Collections package.
- Java cannot have Global functions or Global variables
- Java uses Packages.