Comparison: C++ vs Java

Last updated on:

In this tutorial, today you will learn about the key differences between C++ and Java programming language.

If you have basic knowledge of C ++, then there must have been a question in your mind that how Java is different and more advanced than C ++.

And to know the answer to this question, you should know the basic differences between them.

When I started Java first time, the same question came in my mind and I got that there are many differences and similarities between the C++ programming language and the Java programming language.

Here’s a list of top key differences between C++ and Java listed below:

Comparison IndexC++Java
PlatformC++ is a platform-dependent language.Java is a platform-independent language.
Mainly used forC++ is used for system programming.Java is used for application programming. It is widely used in
applications like window, web-based, enterprise and mobile.
Compiler and InterpreterC++ uses the compiler only. i.e,
C++ compiles and run the code
using compiler only which converts source code into machine code and produces output.
Java uses both compiler and interpreter. The source code is first compiled to get bytecode then, the interpreter executes the bytecode at runtime and produces output.
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 concept in java.
Goto statementsC++ supports Goto statements.Java doesn’t support Goto statements.
Pointers
C++ supports pointer. User can write the pointer program in
C++.
Java doesn’t support pointer externally. User can’t write the pointer program in Java.
Multiple Inheritance C++ supports Multiple Inheritance.Java doesn’t support Multiple Inheritance. It is achieved by using Interface.
OverloadingC++ supports method and operator
overloading.
Java supports only method overloading.
Union and StructureC++ uses the concept of union
as well as structure.
Java doesn’t support structure and union.
Thread SupportC++ doesn’t have in-built threads. Java has in-built thread support.
PortabilityC++ is not portable.Java is portable in nature.
Types of programming languages usedProcedural and Object-orientedObject-oriented
Documentation Comment It doesn’t support documentation comment.It supports documentation comment(/*…/) that creates documentation for Java source code.
Hardware C++ is nearer to the hardware.It is not very interactive with hardware.
Root Hierarchy No root hierarchy.Follows single root hierarchy.
Input MechanismCout and Cin is used here.System.in and System.out is used here.
Header FilesC++ uses header files like #include <iostream.h>.Java has no header files.
ConceptIt uses WOCA (write once, compile anywhere).It uses WORA (write once, run anywhere).

Coding Difference:

For C++,

File: Main.cpp

#include<iostream.h>
#include<conio.h>
void main(){
cout<<"Hello world";
getch();
}

For Java,

File: simple.java

package revise;
public class simple {
    public static void main(String[] args) {
		System.out.println("Hello world");
  }
}

Comments

Leave a Reply

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