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 Index | C++ | Java |
Platform | C++ is a platform-dependent language. | Java is a platform-independent language. |
Mainly used for | C++ 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 Interpreter | C++ 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 Reference | C++ 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 statements | C++ 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. |
Overloading | C++ supports method and operator overloading. | Java supports only method overloading. |
Union and Structure | C++ uses the concept of union as well as structure. | Java doesn’t support structure and union. |
Thread Support | C++ doesn’t have in-built threads. | Java has in-built thread support. |
Portability | C++ is not portable. | Java is portable in nature. |
Types of programming languages used | Procedural and Object-oriented | Object-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 Mechanism | Cout and Cin is used here. | System.in and System.out is used here. |
Header Files | C++ uses header files like #include <iostream.h>. | Java has no header files. |
Concept | It 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");
}
}
Leave a Reply