Friday, September 13, 2019

What is difference between C++ and Java?

ParameterC++Java
RelationshipNo strict relationship between class names and filenames. In C++, header files and implementation files are used for specific class.The strict relationship is enforced, e.g., the source code for class PayRoll has to be in PayRoll.java.
Input mechanismI/O statements use in and cout, e.g., in » x; cout« y;I/O input mechanism is a quite complex as it reads one byte at a time (System.in). Output is easy, e.g. System.out.println(x);
Complier and InterpreterC++only support compilerJava supports both compiler and interpreter
compatibility with other languagesCompatible with C source code, except some exceptional cases.No backward compatibility with any previous language. The syntax is influenced by C/C++.
Access control and object protectionFlexible model with constant protection availableThe cumbersome model encourages week encapsulation.
ConceptWrite once compile anywhereWrite once run anywhere everywhere
Support for programming typeAllows both procedural programming and object-oriented programming.Support object-oriented programming model.
InterfaceAllows direct calls to native system libraries.Only call through the Java Native Interface and recently Java Native Access
Memory managementAccessible to programmerSystem controlled
Root hierarchyC++ there is no such root hierarchy. C++ supports both procedural and object-oriented programming; therefore, it is called a hybrid language.Java is a pure object-oriented Programming language. That's. Why It follows single root hierarchy.
Best featuresC++ supports Object-oriented features Procedural programming features.Java support automatic garbage collection. It does not support destructors as C++ does.
Goto StatementC++ has a goto statement. Although, it is not ideal to a use a goto statement.Java has no goto statement. The keywords got, and const are reserved even if they are not used.
Multiple inheritanceC++ provide multipleInheritance. The keywordvirtual is used to resolveproblems during multipleinheritance if there is any.Java doesn't provide multiple inheritance.
Scope resolution operatorC++ has scope resolution operator (: :) which is used to define a method outside of a class and to access a global variable within from the scope where a local variable also exists with the same name.No scope resolution operator (: :) in Java. The method definitions have to occur within a class, so there is no need for scope resolution.
Use of try and catchIn C++, you can't include the try/catch even if the function throws an exception.In Java, Exception handling is different because there are no destructors. Also, in Java, try/catch must be defined if the function declares that it may throw an exception
Supporting methodC++ supports both method overloading & operator overloadingJava only supports method overloading. It does not provide support for operator overloading.
PortabilityThe source must be recompiled for the platform; hence the code is not portable.Bytecode classes are transferrable to platform-specific JVM's.
Type semanticsConsistent between primitive and object types.Differ for primitive and object types.
LibrariesPredominantly low-level functionalityMassive, classes for high-level services.
Runtime error detectionProgrammer responsibility.System Responsibility.
SupportsPoints, structure, and union.Threads and interfaces.
Functions & DataFunctions and data may exist external to any class, global and namespace scopes are available.All function and data exist within classes; package scope are available.
PlatformC++ programs are platform dependent. They need to be compiled for a particular platform.Java programs are platform independent. Java programs are written for Java Virtual Machine (JVM). It will run without needing recompilation.
Runtime error detectionIn C++, It is Programmer responsibility to check the errors.It is system responsibility to check error in the program.
PointerC++ support pointers.Java offers only limited support for pointers.
StructureIt supports structures.It does not any support for structures.
UnionsC++ supports unions.Java does not support unions.
Object managementC++ supports manual object management with the help of new and delete keywords.Java is heavy depend on automatic garbage collection. It does not support destructors.

No comments:

Post a Comment

How to DROP SEQUENCE in Oracle?

  Oracle  DROP SEQUENCE   overview The  DROP SEQUENCE  the statement allows you to remove a sequence from the database. Here is the basic sy...