Java v/s C++

Apart from being platform independent , what are the other features that makes Java a better approach than C++?


4 Answers
1-4 of  4
4 Answers
  • C++ was designed for systems and applications programming, extending the C programming language. 
    Java was created initially as an interpreter for printing systems.It is secure and highly portable. 
    Java is a object-oriented language that uses similar (but incompatible) syntax to C++.

    1.C++ supports pointers whereas Java does not pointers. But when many programmers questioned how you can work without pointers, the promoters began saying "Restricted pointers.” So we can say Java supports Restricted pointers.
    2. At compilation time Java Source code converts into byte code .The interpreter execute this byte code at run time and gives output .Java is interpreted for the most part and hence platform independent. C++ is run and compiled using compiler which converts source code into machine level languages so c++ is platform dependent.
    3.Java uses compiler and interpreter both and in c++ their is only compiler
    4.C++ supports operator overloading multiple inheritance but java does not.
    5.C++ is more nearer to hardware then Java
    6.Everything (except fundamental types) is an object in Java (Single root hierarchy as everything gets derived from java.lang.Object).
    7.Java does is a similar to C++ but not have all the complicated aspects of C++ (ex: Pointers, templates, unions, operator overloading, structures etc..) Java does not support conditional compile (#ifdef/#ifndef type).
    8.Thread support is built-in Java but not in C++. C++11, the most recent iteration of the C++ programming language does have Thread support though.
    9.Internet support is built-in Java but not in C++. However c++ has support for socket programming which can be used.
    10.Java does not support header file, include library files just like C++ .Java use import to include different Classes and methods.
    11.Java does not support default arguments like C++.
    12.There is no scope resolution operator :: in Java. It has . using which we can qualify classes with the namespace they came from.
    13.There is no goto statement in Java.
    14.Exception and Auto Garbage Collector handling in Java is different because there are no destructors into Java.
    15.Java has method overloading, but no operator overloading just like c++.
    16.The String class does use the + and += operators to concatenate strings and String expressions use automatic type conversion.
    17.Java does not support unsigned integer.

  • Java and C++ both are object-oriented programming language but there are differences between these two languages which are listed below

    1. Pointers: C++ Supports pointer while Java doesn't

    2. C++ uses compiler while Java uses both compiler and interpreter.

    3. C++ supports header files while in case of Java there are no header files supported

    4. C++ has a goto statement while Java does not have any kind of goto statement.

    5. Java supports automatic garbage collection and has no support for destructors as in the case of C++ it has destructors.

    6.   C++ has a scope resolution operator :: while in the case of Java there is no scope resolution operator.

  •   C++ is compatible with C source code, whereas, java provides the Java Native Interface and recently Java Native Access as a way to directly call C/C++ code. C++ is Write once, compile anywhere, as Java is Write once, run anywhere/everywhere. C++ runs as native executable machine code for the target instruction set as java runs in a virtual machine. In terms of conversion, allows explicitly overriding types as well as some implicit narrowing conversions(for compatibility with C) but, java strongly follows rigid type safety except for widening conversions. C++ uses single and multiple inheritance of classes, including virtual inheritance and java uses single inheritance of classes. Supports multiple inheritance via the Interfaces construct, which is equivalent to a C++ class composed of abstract methods. In C++, const keyword for defining immutable variables and member functions that do not change the object. Being Const is propagated as a means to enforce, at compile-time, correctness of the code with respect to mutability of objects as in java, final provides a version of const, equivalent to type* const pointers for objects and const for primitive types. Immutability of object members achieved through read-only interfaces and object encapsulation.

  • Java is more secure and robust language. It also support private method in interface, it's performance is increased according to java 9.

1-4 of  4
Programming in Java
Practice Mock Test
Programming in Java