Friday, 11 November 2011

Difference Between C++ and Java


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++

Difference Between C++ and Java
  1. C++ (earliar known as C with Classes) was developed by Bjarne Stroustrup in 1979 at Bell Labs.
  2. C++ make use of Pointers and References
  3. C++ binary is not portable meaning binary cannot be run on different OS Platforms.
  4. C++ supports Multiple Inheretence through usage of Virtual Inheritance.
  5. Dynamic Polymorphism is achieved using Virtual Keyword (use of Virtual Pointer [VPTR] and VTable)
  6. 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)
  7. C++ uses Collections by using STL (Standard Template Library). Its a third-party API
  8. C++ can have Global functions or Global variables which are outside the class
  9. C++ uses namespaces.

Java

Difference Between C++ and Java
  1. Java was developed by James Gosling in 1995 at Sun Microsystems (now acquired by Oracle Corporation).
  2. Java uses only References. Pointers are eliminated in Java to remove the complexity from the Programmers.
  3. Java code is portable and is achieved using Java Bytecode (.class) file which can be executed by JVM (JVMs differ based on the OS).
  4. Java doesn’t support Multiple Inheretence (because of Daimond Problem), But supportsInterface Inheritance using Interface.
  5. Dynamic Polymorphism is achieved using Method Overiding
  6. 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.
  7. Java API comes with Collections package.
  8. Java cannot have Global functions or Global variables
  9. Java uses Packages.

No comments: