Difference between C++ and Java

By | April 6, 2015
In this tutorial I am going to share difference between C++
and Java. C++ programming language was developed by Bjarne Stroustrup in the
year 1983 and Java Language was developed by James Gosling in the year 1995.
Both C++ and Java are object oriented programming language but still there are
lot of differences between them.
difference between c++ and java

Difference between C++ and Java

C++ is a procedural and object oriented programming language.
Java is pure object oriented programming language.
C++ support structure, union, template, preprocessor, default
arguments, operator overloading and pointers.
Java doesn’t support all these features. Java has concept of “restricted
pointers” that uses references which acts like pointers. But we can’t perform
arithmetic operations on it.
C++ support destructor, which is called to destroy the objects.
Java doesn’t support destructor because it supports automatic garbage
In C++ we can declare global variables and can define methods outside
the class using scope resolution operator (::).
Java doesn’t have scope resolution operator and we can declare global
variables. The methods can only be defined inside the class.
C++ support goto statement. Use of goto is not considered good because
it makes difficult to understand the program.
goto and const keywords are reserved in Java but they are not used.
C++ supports multiple inheritance and it can be implemented using
Java doesn’t support multiple inheritance. Although it can be
implemented using interface.
C++ is a platform dependent language. Write once, compile anywhere
Java is a platform independent language. Write once, run anywhere /
everywhere (WORA / WORE).
C++ only uses compiler.
Java uses both interpreter and compiler.
C++ doesn’t have built in thread support. We have to use third party
libraries for thread support. In C++ 11, the thread support is added as a built in feature.
Java has built in thread support. There is a Thread class which is
used to implement multithreading.

These are few difference between C++ and Java. If you find
any mistake in above tutorial or know about any other difference between Java and C++ then please comment

9 thoughts on “Difference between C++ and Java

    1. István Fajth

      Sort of correct.
      The static variables and methods are considered globally available and often mentioned as global things, but the truth is that they are part of a Class object that is created by the ClassLoader, and represents the class T.

  1. István Fajth

    6. I did not check how it works with the static implementations on the interfaces introduced in Java 8, but I think that does not modify the fact that multiple inheritance in Java is possible only by implementing multiple interfaces, but not by extending multiple super classes. But with this addition, the inheritance of two methods with the same name introduced in Java, but since these are static implementations, they can be reffered via the interface, and it is discouraged to reference them via the class that implements the interface, and also they can not be overridden by the class, so it causes much less headache.
    7. Java is also reffered by Java developers as "Write Once Suck Everywhere" because it has multiple different glitches that affects different platforms (belive me I have ran into a few in the years), and it also has some rough APIs that are designed as they are because of fundamental platform differences, but this is just a fun fact (and source of infinit hatred when you run into one), most of the codes are running smoothly on every supported systems.
    8. I would add that it uses the Java Virtual Machine as the platform, and compiles the Java code to the language of the virtual machine that interprets the compiled virtual machine code and runs the application on the given platform. So for Java they choose not to create the compiler for every supported platform, but they choose to create a virtual machine that is compiled for every supported platform, and which is able to run the virtual machine code on that platform it is written to.
    This concept is very useful, since it made possible a lot of projects such as Jython, Groovy and so on that are extending the Java language and runs on the java vitual machine (jvm), but adds lot of things to the language itself. The developers needed to write only one compiler that creates the JVM code from the given language code, and in this way those languages can support Java elements natively.
    9.Java extensively supports multithreading, it has lots of constructs that is by design support multithreading. (concurent collections, Executors, Future, Semaphore just to mention some of them) In Java 8 lambda expressions and the Stream API also introduced that supports multithreaded execution. But the list is long I think. One main thing to mention: every java program is running in multiple threads, even if you do not aware of the fact, there are a few threads that are used to manage to operating program while it is being ran by the JVM.

    For the C++ part I can not tell much, I am working with Java too long time ago and forget that small little knowledge that I had, so I decided not to touch that part of the topic 🙂


Leave a Reply

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