Java – C++ & Java Comparison

  • Post category:Java
  • Reading time:5 mins read

There are many differences and similarities between the C ++ and Java programming language. Below is a list of the main differences between C ++ and Java.

PropertyC++Java
Platform-independentIt is platform-dependent.It is platform-independent.
Mainly used forIt is mainly used for system programming.It is mainly used for application programming. It is manly used in window, web-based, enterprise and mobile applications.
Design PurposeIt was designed for systems and applications programming. It was designed with a goal of being easy to use and develop Web application that can be accessed from everywhere
Goto & ConstIt supports the Goto & Const KeywordIt doesn’t support the Goto & Const Keyword.However, in Java,  final keyword is used instead Const.
Multiple inheritanceIt supports both single and multiple inheritanceIt doesn’t support multiple inheritance through class. Multiple inheritance is partially done through interfaces
Operator OverloadingIt supports operator overloading.It doesn’t support operator overloading.
PointersIt supports pointer. You can write pointer program in C++. However, you can’t write the pointer program in java but It supports pointer internally.
Compiler and InterpreterIt uses compiler only which converts source code into machine code It uses compiler and interpreter both. At compilation time , java source code is converted into bytecode and interpreter executes this bytecode at runtime and produces output.
Call by Value and Call by referenceIt supports both call by value and call by reference.It supports call by value only.
Structure and UnionIt supports structures and unions.It doesn’t support structures and unions.
Thread SupportThere is no built-in thread support. We can achieve using third party libraries.It has built-in thread support.
Documentation commentIt doesn’t support documentation comment.It supports documentation comment (/** … */) to create documentation for java source code.
LibrariesComparatively available with low level functionalitiesJava Platform provides a comprehensive set of standard class libraries
Memory AllocationIt allows memory allocation for primitive data types at compile time and it is called as Static programming languageIt allows memory allocation for primitive data types at runtime and it is called as Dynamic programming language

C++ Example

File: main.cpp

#include<iostream>
using namespace std;
//This is where the execution of program begins with main method
int main()
{
cout<<"Hello World using C++ !";
return 0;
}

Output

Hello World using C++ !

Java Example

File: Test.java

class Test{
public static void main(String args[]){
System.out.println("Hello World using Java !");
}
}

Output

Hello World using Java !