answersLogoWhite

0


Best Answer

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++.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

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

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

The central differences between Java and C++ are:

  1. Memory Management: Java is a memory-managed language, meaning that it uses automatic garbage collection. C++ programmers have to take care of memory issues themselves.
  2. Destructors: As a result, Java does not need destructors to do memory cleanup, so it does not have destructors.
  3. Inheritance: Java does not allow multiple inheritance. It has interfaces as a partial substitute to C++'s multiple inheritance.
  4. Objects: Every non-primitive variable in Java is an object. Java has no "free functions" that are out of the scope of a class or object.
  5. JVM: Java is built on the concept of using a virtual machine, the JVM. C++ is planned to be compiled to native machine code. This makes Java more portable and more secure. OTOH, this makes C++ faster than Java, but this is only noticeable in heavy-computation programs.

Java is pure object oriented language, and C++ is not, because you can access the private member of classes in c++ by using the friend function. There is no such function within java.
This answer is:
User Avatar

User Avatar

Wiki User

14y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Difference between Java and the C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


Difference between java and C plus plus?

java is an advanced object oriented programming language than c++


Difference between procedure and function in C or C plus plus or Java language?

In C there are functions only, In Java methodsonly (static methods as well), in C++ both.


What are the main differences between Java and C plus plus?

the difference is that c plus is better because you get big grades


Major difference between c and java?

Java is object oriented, C is not...


What is the difference between cc plus plus and java?

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.


Is Java better than c plus plus?

It is a different tool with difference strengths and weaknesses.


What is difference between exception handling in C and Java?

Easy: there is no exception-handling in C.


Which is easier 'C plus plus' or 'Java'?

Java is considerably easier than C++.


Which is more popular c plus plus or java?

Java


What is the difference between pointers in c and c plus plus?

Nothing.


Is it necessary for you to learn c and c plus plus before you go for java?

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.