cpp_vs_java

How is java different from c++

Features removed in java:

  • Java doesn’t support doesn’t pointers to avoid unauthorized access to memory locations.
  • Java does not include structures, unions, and enum data types.
  • Java does not support operator overloading.
  • Preprocessor plays a less important role in C++ and so eliminated entirely in java.
  • Java does not perform automatic type conversions that result in a loss of precision.

New features added in Java:

  • Multithreading, allows two or more pieces of the same program to execute concurrently.
  • C++ has a set of library functions that use a common header file. But java replaces it with its own set of API classes.
  • It adds packages and interfaces.
  • Java supports automatic garbage collection.
  • break and continue statements have been enhanced in java to accept labels as targets.
  • The use of Unicode characters ensures portability.
  • Java does not support global variables. Every method and variable is declared within a class and forms part of that class.
  • Java does not allow default arguments.
  • Java does not support the inheritance of multiple superclasses by a subclass (i.e., multiple inheritances). This is accomplished by using the ‘interface’ concept.
  • It is not possible to declare unsigned integers in java.
  • In Java, objects are passed by reference only. In C++ objects may be passed by value or reference.

Features that differ:

  • Though C++ and java support Boolean data type, C++ takes any nonzero value as true and zero as false. True and false in java are predefined literals that are valued for a Boolean expression.
  • Java has replaced the destructor function with a finalize) function.
  • C++ supports exception handling that is similar to javas. However, in C+ there is no requirement that a thrown exception be caught.

C++ vs Java:

ComparisonIndexC++Java
Platform- independentC++ is platform-dependent.Java is platform-independent.
Mainly used forC++ is mainly used for system programming.Java is mainly used for application programming. It is widely used in Windows, web-based, enterprise, and mobile applications.
GotoC++ supports the goto statement.Java doesn’t support the goto statement.
Compiler and InterpreterC++ uses compilers only.Java uses a compiler and interpreter both.
Call by Value and Call by referenceC++ supports both call-by-value and call-by-reference.Java supports call-by-value only. There is no call by reference in java.
Structure and UnionC++ support structures and unions.Java doesn’t support structures and unions.
Thread supportC++ doesn’t have built-in support for threads.Java has built-in thread support.
Documentation commentC++ doesn’t support documentation comments.Java supports documentation comment (/**. . */) to create documentation for java source code.
unsigned right shift >>>C++ doesn’t support >>> operatorJava supports unsigned right shift >>> operator

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top