Classes are the basic unit of code in Java, whereas the basic unit of code in C++ are functions.
All objects in Java descend from a common class (Object), which allows more generic code. While this can also be (manually) implemented within C++, generic programming is best achieved using templates and concepts.
All methods in Java (including destructors) are virtual by default. In C++, methods must be explicitly declared virtual if they are expected to be overridden, or explicitly declared final if they must not be overridden.
Java does not permit operator overloading, thus we cannot operate upon objects as intuitively as we can in C++.
FeatureC
C++JavaParadigmsProcedural
Procedural, OOP, Generic ProgrammingOOP, Generic Programming (from Java 5)Form of Compiled Source CodeExecutable Native Code
Executable Native CodeJava bytecodeMemory managementManual
ManualManaged, using a garbage collectorPointersYes, very commonly used.
Yes, very commonly used, but some form of references available too.No pointers; references are used instead.PreprocessorYes
YesNoString TypeCharacter arrays
Character arrays, objectsObjectsComplex Data TypesStructures, unions
Structures, unions, classesClassesInheritanceN/A
Multiple class inheritanceSingle class inheritance, multiple interface implementationOperator OverloadingN/A
YesNoAutomatic coercionsYes, with warnings if loss could occur
Yes, with warnings if loss could occurNot at all if loss could occur; msut cast explicitlyVariadic ParametersYes
YesNoGoto StatementYes
YesNo
JAVA is very different from C++ because of following reasons.
1-) C++ is plateform depedent language but JAVA is plaateform independent language.
2-) JAVA is much secure in comparision to C++.
3-) JAVA uses JVM machine.
4-) Java genrate byte code from the source code which are further converted in to machine code.
The central differences between Java and C++ are:
Difference between Java and C++ is that Java does not support pointers. Pointers are inherently insecure and troublesome. Since pointers do not exist in Java, neither does the -> operator. Some other C++ features are not found in Java.
• Java does not include structures or unions because the class encompasses
these other forms. It is redundant to include them.
• Java does not support operator overloading.
• Java does not include a pre-processor or support the pre-processor directives.
• Java does not perform any automatic type conversions that result in a loss of precision.
• All the code in a Java program is encapsulated within one or more classes. Therefore, Java does not have global variables or global functions.
• Java does not support multiple inheritances.
• Java does not support destructors, but rather, add the finalize() function.
• Java does not have the delete operator.
• The << and >> are not overloaded for I/O operations.
• Java does not support templates.
C++ has address-of (&) and dereference (*) operators. Java does not. Java treats all objects as reference handles to some kind of internal pointer table, but the programmer does not see that.
C++ has pointer types and thus has element-of-via-pointer (->) operators. Java treats all objects as references and uses element-of-via-reference (.) operators. (C++ has (.) also.)
C++ supports multiple inheritance. Java does not.
C++ does not natively support smart pointers and automatic garbage collection. You must explicitly deallocate memory, and garbage collect on your own. Java automatically garbage collects objects that go out of scope, and they don't need to be deallocated.
C++ supports template classes, that allow you to define classes behaviours for different types. Java provides generics, which gives similar, though not identical, capability.
The class libraries of C++ and Java are substantially different. They are so different that knowledge in one language does not constitute knowledge in the other, even though the language syntax is nearly identical, because the platform is more important that the language.
C++ is usually a compiled language, while Java is usually interpreted. C++ is usually faster, while Java is usually more portable, even at the byte code (or object) level.
Java objects are always instantiated dynamically (on the heap), whereas C++ objects can be instantiated both statically (on the stack) or dynamically, as required.
Java always uses heap allocated references to manage dynamic objects. When all references to an object have fallen from scope, the garbage collector releases the dynamic allocation. C++ has no built-in garbage collector thus all dynamic objects must be manually released. However, statically allocated objects are automatically released as soon as they fall from scope.
Java object members are always initialised by assignment, whereas C++ object members are always initialised via initialisation lists. C++ programmers can explicitly declare initialisation lists to improve efficiency during construction, using assignment only where it is necessary to do so. Java object members are always implicitly zeroed prior to assignment, which is less efficient and akin to two-stage initialisation in C++, using both an initialisation list (implicitly or explicitly) as well as assignment.
All Java class methods are implicitly virtual and can only be declared non-virtual by declaring them final (or private). In C++ all class methods are implicitly non-virtual but can be explicitly declared virtual as required.
Virtual methods are treated differently during construction. In C++, all virtual methods are treated as if they were non-virtual for the purpose of construction. This is because derived classes do not exist until their base classes are fully constructed in C++. Thus all virtual calls will invoke the base class method instead of the expected override, which could lead to unexpected behaviour during construction. By contrast, Java will always invoke the derived class override, but this can also lead to unexpected behaviour because, although the derived class will exist at that point, it may not be fully initialised (all its members will be zeroed, awaiting assignment).
Note that this answer is not exhaustive by any means and may well be updated in the future.
Although they both use a similar syntax, Java uses a simpler object model and is highly abstract. Java compiles to byte code suitable for running within the Java Virtual Machine (JVM). While this makes the code highly-portable without the need to recompile for each platform, the need for the JVM adds an extra layer of abstraction which reduces performance. By contrast, C++ is much less abstract with a high degree of control which permits the inclusion of low-level code for specific architectures. Although code must be conditionally compiled for each platform, the resulting compilation is native machine code with an extremely high performance, akin to that of assembler.
C plus supports the use of pointers, where as java does not. because the use of pointers may makes the coding difficult. C plus supports multiple inheritance. where as java does not supports multiple inheritance. java is platform independent.
In C there are functions only, In Java methodsonly (static methods as well), in C++ both.
C is a procedure oriented language ,Where C++ & java are object oriented language.But java is platform independent.So generally C is called POP.C++ is called OOP.But java is OOP , which is platform independent.If java does not support primitive data type then it is called as pure object oriented language.
Easy: there is no exception-handling in C.
C, C++ and Java are cross-platform languages. NET is for Windows-only.
C++.
Java doesn't have pointers. C++ has pointers.
java is an advanced object oriented programming language than c++
In C there are functions only, In Java methodsonly (static methods as well), in C++ both.
the difference is that c plus is better because you get big grades
Java is object oriented, C is not...
C is a procedure oriented language ,Where C++ & java are object oriented language.But java is platform independent.So generally C is called POP.C++ is called OOP.But java is OOP , which is platform independent.If java does not support primitive data type then it is called as pure object oriented language.
It is a different tool with difference strengths and weaknesses.
Easy: there is no exception-handling in C.
Java is considerably easier than C++.
Java
Nothing.
No. You can learn Java first if you want. However, from a language perspective, C++ and Java are nearly identical1, and C is the predecessor of C++, so some people feel that the proper sequence is C, then C++, then Java. It is entirely up to you. ----------------------------------------------------------------------------- 1Nearly identical, that is, from a language perspective only. The environment and libraries are vastly different between C++ and Java.