C++ vs Java (Cont.)


A list of top differences between C++ and Java is given below:

Comparison Index C++ Java
Call by value/reference Supporting both Supporting call by value only, but no call by reference
Compiler/interpreter Using compiler only. C++ is compiled and run using the compiler which converts source code into machine code so, C++ is platform dependent. Using compiler and interpreter both. Java source code is converted into bytecode at compilation time. The interpreter executes this bytecode at runtime and produces output. Java is interpreted that is why it is platform independent.
Design goal For systems and applications programming Being easy to use and accessible to a broader audience
Hardware Nearer to hardware Not so interactive with hardware
Goto statement Supporting Not supporting
Libraries Comparatively available with low-level functionalities Providing wide range of classes for various high-level services
Major usage System programming Application programming
Memory management Managed by developers using pointers. Supports structures and union. Controlled by system, does not use pointers. Supports threads and interfaces.
Multiple inheritance Supporting Not supporting multiple inheritance through class, but it can be achieved by interfaces
Object-oriented Yes Yes. Everything (except fundamental types) is an object in Java. It is a single root hierarchy as everything gets derived from java.lang.Object.
Operator overloading Supporting Not supporting
Pointers Supporting Not supporting
Polymorphism Explicit for methods, supports mixed hierarchies Automatically using static and dynamic binding
Portability Platform dependent as source code must be recompiled for different platforms Uses concept of bytecode which is platform independent and can be used with platform specific JVM.
Program handling Methods and data can reside outside classes. Concept of global file, namespace scopes is available. All methods and data reside in class itself. Concept of package is used.
Runtime error detection mechanism Programmers’ responsibility System’s responsibility
Structure and union Supporting Not supporting
Thread support Not having built-in support for threads. It relies on third-party libraries for thread support. Having built-in thread support
Type semantics Supports consistent support between primitive and object types. Different for primitive and object types


Review: C++ vs Java
    Which feature is directly supported by Java?

      Operator overloading
      Pointers
      Structure and union
      Thread support
        Result:




      Man: “Hi, do you want to dance?”
      Woman: “Yeah, sure!.”
      Man: “Great, go and dance, I want to talk to your pretty friend!.”