This is a comparison of the Java programming language to the C++ programming language.

Table of contents
1 Advantages of Java
2 Disadvantages of Java
3 Advantages of C++
4 Disadvantages of C++
5 Differences between the languages
6 External References:

Advantages of Java

  • The extensive and standardized Java API makes it considerably easier to program in Java than in C++. The standard Java API included with every modern JVM includes built in, standardized libraries for TCP/IP network sockets and services, XML parsing, logging, SQL database access, cryptography, and many other areas. C++ libraries which perform similar functions to the Java API are usually available, but there are typically several competing and mutually incompatible versions with overlapping functionality which cannot easily be used together.
  • Garbage collection facilitates programming and the safety of program execution considerably as programmers do not need to dynamically allocate memory and then remember to free it later.
  • Java is easier to teach and learn because of its streamlined syntax. It inherits less baggage from the C language, most notably in bypassing the need to deal with pointers.
  • The lack of pointers means that buffer overflow bugs (and, consequently, security exploits) are practically impossible in Java. Built in bounds checking prevents an errant program from overwriting the end of a memory buffer or assigning the value of an incompatible data type to a variable.
  • These built in checking mechanisms in Java make it a more robust software environment. On the other hand, they also make Java execution slower (see below).
  • Java can be programmed for multiple plaforms with little regard towards platform-specific characteristics like hardware data types, floating point implementations, or OS libraries. Java programs are compiled into binary bytecode which will execute properly on any standards-compliant JVM, on any architecture, without modification.

Disadvantages of Java

  • Access to native operating system and hardware functions requires a non-Java access library be coded to the JNI (Java Native Interface) API specification. Java programs cannot directly access such services.
  • No compile-time "template" generic containers. (this is slated for inclusion in version 1.5 due to popular demand.)

Advantages of C++

Disadvantages of C++

Differences between the languages

  • C++ has operator overloading. This was not included in Java in order to keep code more readable. While there can be little doubt that this feature is often misused in C++, decreasing readability, there are also numerous good uses, such as in mathematical and scientific programming, where its use improves readability. Because the biggest application area for the Java programming language is business software, operator overloading is still considered by the language designers to be unnecessary, though many hold this position in contention.
  • All objects in Java are pass-by-reference, and are dynamically allocated.
  • Java constants (the "final" keyword) are only enforced within class scope.
  • C++ has flexible support for pointer manipulation, while Java only allows one to assign object references.
  • There is no "goto" in Java (though it is a reserved keyword and barred from use.)
  • C++ supports multiple inheritance while Java uses "interfaces". They each have their advantages and disadvantages. Multiple inheritance is often more logical and representative of how one conceptualizes a problem. However it also complicates member overloading and inheritance, and even its proponents only recommend its use sparingly. Java interfaces significantly simplify its single inheritance model syntax, but can result in larger and less intuitive source code.
    • Some degree of multiple inheritance functionality can also be gained by using "inner classes"

External References: